我发现使用 Apache 服务器管理多个 PHP 版本的解决方案是运行 PHP-FPM 和 FastCGI 而不是mod_php
. 通过这种方式,我可以运行多个版本的 PHP,并在我的开发机器上选择要运行哪个版本的 PHP。
您将需要使用+fpm
phpbrew 标志而不是重新编译您的 PHP 版本,+apxs2
使用命令启动它们phpbrew fpm start
,安装 Apachelibapache2-mod-fastcgi
包,并可能禁用 apache mod_php
- 但一旦它工作,它就非常漂亮。只需配置指向相同代码但不同 PHP-FPM 套接字的不同虚拟主机,我就可以使用多个版本的 PHP 测试同一个站点。
下面是一个 Apache 2.4/etc/apache2/mods-enables/fastcgi.conf
配置文件的示例,其中包含通过 phpbrew 安装的 2 个版本的 PHP:
<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
FastCgiIpcDir /var/lib/apache2/fastcgi
AddType application/x-httpd-fastphp5 .php
Action application/x-httpd-fastphp5 /php5-fcgi
# This is for php 5.6.28
FastCgiExternalServer /usr/lib/cgi-bin/php56-cgi -socket /home/{USERNAME}/.phpbrew/php/php-5.6.28/var/run/php-fpm.sock -pass-header Authorization
# This is for php 7.0.13
FastCgiExternalServer /usr/lib/cgi-bin/php70-cgi -socket /home/{USERNAME}/.phpbrew/php/php-7.0.13/var/run/php-fpm.sock -pass-header Authorization
# this seems to be required by Apache 2.4.10
<Directory /usr/lib/cgi-bin>
Require all granted
</Directory>
</IfModule>
然后在您的 apache“站点”Virtualhost 配置中,您可以指定使用别名运行的 PHP 版本,如下所示:
<VirtualHost *:80>
# ServerName, ServerAdmin, etc
DocumentRoot /var/www/my-site-code
# Then point the php5-fcgi handler to a specific version of PHP
# Here is PHP7, as defined in the fastcgi.conf file
Alias /php5-fcgi /usr/lib/cgi-bin/php70-cgi
</VirtualHost>