如何从htaccess为多个PHP版本配置Apache [英] How to configure Apache for Multiple PHP version from htaccess
问题描述
我已经安装了Remi存储库中的PHP版本集合,该问题本身可能会被忽略,但是为了理解我尝试过的处理过程而保留了该版本.
I have installed a collection of PHP versions from Remi Repositories, which may be ignored, for the question itself, but kept for the sake of understanding the processed I tried.
它们可以从命令行正常运行,但是我想将它们与Apache 2(Fedora 24上的httpd)一起使用,并运行多个虚拟主机,如下所示:
They work fine from command line, but I'd like to use them with Apache 2 (httpd on Fedora 24), running multiple virtual hosts as in:
php54.test
php55.test
php56.test
php70.test
php71.test
我已经创建了VirtualHost conf文件,并且每个文件都工作正常.
I have created the VirtualHost conf files and each one is working fine.
我想运行每个对应的php版本(根据建议的ServerName),但是我找不到如何从每个虚拟主机加载PHP的方法. 我找不到相应的Remi libphpX.so来将它们作为模块加载:
I want to run each corresponding php version (accordingly to the suggestive ServerName), but I can't find how to load PHP from each Virtual Host. I couldn't find the corresponding Remi libphpX.so for loading them as modules:
<VirtualHost *:80>
ServerName php54.test
DocumentRoot /var/www/php54
#SOMETHING LIKE THIS...
LoadModule php??_module modules/libphp??.so
</VirtualHost>
我有一个共享托管,这不是新闻,它使我可以从.htaccess更改PHP版本,并且我可以执行以下操作:
I have, and this is not news, a shared hosting that allows me to change PHP version from .htaccess and I can do something like this:
AddHandler application/x-httpd-php54 .php
AddHandler application/x-httpd-php55 .php
AddHandler application/x-httpd-php56 .php
AddHandler application/x-httpd-php7 .php
AddHandler application/x-httpd-php71 .php
我现在看起来像是一个虚拟人,但是如何使用相同的.htaccess切换来提供多个PHP版本呢?
I may look like a dummy now, but how can I do the same .htaccess switching for having multiple PHP versions available?
我可能不知道在Google上搜索什么以及如何找到最匹配的答案.
I probably am not knowing what and how to search on Google to find the best matched answer.
推荐答案
您不能使用mod_php的多个版本.
You cannot use multiple versions of mod_php.
更好的解决方案是使用php-fpm(Fastcgi进程管理器),在每个虚拟主机中使用一个SetHandler到fcgi服务器:
Better solution is to use php-fpm (the Fastcgi Process Manager), using in each vhost a SetHandler to fcgi server:
SetHandler "proxy:fcgi://127.0.0.1:9070"
或(使用Unix域套接字)
Or (using unix domain socket)
SetHandler "proxy:unix:/var/opt/remi/php70/run/php-fpm/www.sock|fcgi://localhost"
本文对此进行了说明:我的PHP工作站.
This is described in this article : My PHP workstation.
这篇关于如何从htaccess为多个PHP版本配置Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!