Question

How to run together: PSGI and PHP?

I have Perl/PSGI application (running under pure perl Starman server). Now, for some reason need run one PHP application too ;(, so (probably) need Apache2. Questions:

  • really need Apache for PHP? or exists some other solution?
  • How to setup reverse proxy, so when someone will go to http: //mysite/myapp/something, will be proxied to Starman where my PSGI "myapp" living? and
  • http: //mysite/phpapp/anything - will go to php app...
  • I can setup the Starman server for listening on another port, e.g. 8080, but want access both applications at port:80 - so need reverse proxy.

Plus:

the server is behind my home NAT router. Internal server has address: 192.168.1.10, from the outside, ofc, the router have correct internet address. I have redirected all traffic

routerIP:80 -> 192.168.1.10:80
  • What is best way achieve access to both applications: PSGI + PHP from the both side (internet + "intranet") at the port:80?
  • Need setup some virtual hosts? Or exists some really simple solution?
  • some links to helpful guidelines shoudl help a lot too..

Ps: I don't need optimize performance, the server is only for home/demo/testing purpose.

EDIT: Now, in another similar situation I checked CPAN again and based on @rawhide's answer I found the Plack::App::PHPCGI module. Works great - it is really cool testing php apps under plackup... ;)

Was it helpful?

Solution

You can execute it as CGI (fork+exec) either using Plack::App::CGIBin or using WrapCGI directly

my $rawapp = Plack::App::WrapCGI->new(script => "rawhide.php" , execute => 1 )->to_app;
builder {
    mount "/rawhide" => $rawapp ;
};

If rawhide.php has no shebang, you'd use /usr/bin/php /path/to/rawhide.php

OTHER TIPS

The easiest would be to run Apache2 and PHP on port 80, and install mod_proxy to the Apache process and reverse proxy some of the path to the backend Starman. You can also run php using php-fpm as a FastCGI, and do the same thing.

Since it is a demo purpose, you can go crazy and run Starman on port 80 instead, and then use Plack::App::FCGIDispatcher to "mount" the FastCGI PHP process. I tried that once - it worked well, but probably only for the demo purpose, not for the production use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top