如何一起运行:PSGI 和 PHP?
我有 Perl/PSGI 应用程序(在纯 perl Starman 服务器下运行)。现在,由于某种原因也需要运行一个 PHP 应用程序;(,所以(可能)需要 Apache2。问题:
- PHP 真的需要 Apache?还是存在其他解决方案?
- 如何设置反向代理,以便当有人访问 http:// /mysite/myapp/something,将被代理到我的 PSGI“myapp”所在的 Starman?和
- http://mysite/phpapp/anything - 将转到 php 应用程序...
- 我可以设置 Starman 服务器以侦听另一个端口,例如8080,但想要在端口:80 访问这两个应用程序 - 因此需要反向代理。
另外:
服务器位于我的家庭 NAT 路由器后面。内部服务器的地址为:192.168.1.10,从外部来看,ofc,路由器具有正确的互联网地址。我已重定向所有流量
routerIP:80 -> 192.168.1.10:80
- 实现对两个应用程序的访问的最佳方法是什么:从端口:80 的两端(互联网+“内联网”)
- 访问 PSGI + PHP?或者确实存在一些虚拟主机?简单的解决方案?
- 一些有用指南的链接也应该有很大帮助。
Ps:我不需要优化性能,服务器仅用于家庭/演示/测试目的。
编辑:
现在,在另一个类似的情况下,我再次检查了 CPAN,并根据 @rawhide 的回答,我发现了 Plack::App::PHPCGI 模块。效果很好 - 在 plackup 下测试 php 应用真的很酷...;)
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... ;)
发布评论
评论(2)
您可以使用
Plack::App::CGIBin
或直接使用 WrapCGI 将其作为 CGI (fork+exec) 执行。如果 rawhide.php 没有 shebang,则可以使用
/usr/bin /php /path/to/rawhide.php
You can execute it as CGI (fork+exec) either using
Plack::App::CGIBin
or using WrapCGI directlyIf rawhide.php has no shebang, you'd use
/usr/bin/php /path/to/rawhide.php
最简单的方法是在端口 80 上运行 Apache2 和 PHP,并将 mod_proxy 安装到 Apache 进程,并反向代理一些到后端 Starman 的路径。您还可以使用 php-fpm 作为 FastCGI 来运行 php,并执行相同的操作。
由于它是演示目的,您可以疯狂地在端口 80 上运行 Starman,然后使用 Plack::App::FCGIDispatcher 来“挂载”FastCGI PHP 进程。我尝试过一次 - 它运行良好,但可能仅用于演示目的,不适用于生产用途。
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.