本文介绍了CentOS 7上使用Apache的多个PHP版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指导我在CentOS 7上使用一个apache实例安装和配置Multi PhP的方法,以及测试它的正确方法.

Can anyone here instruct me way to install and configure Multi PhP with one apache instance on CentOS 7, and the proper way to test it..

推荐答案

安装所有必需的存储库和软件包

非常感谢 https://rpms.remirepo.net/wizard/

以下命令假定您已经sudo su -,否则您将必须在每个命令中添加sudo:

install all the necessary repos and packages

big thanks to https://rpms.remirepo.net/wizard/

the following commands assume you already sudo su - or you will have to add sudo to each of the commands:

yum install httpd -y
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils -y
yum install php56 -y
yum install php72 -y
yum install php56-php-fpm -y
yum install php72-php-fpm -y

停止两个fpm服务器

systemctl stop php56-php-fpm
systemctl stop php72-php-fpm

默认情况下,它在127.0.0.1端口9000上侦听,使它们在不同的端口上侦听

sed -i 's/:9000/:9056/' /etc/opt/remi/php56/php-fpm.d/www.conf
sed -i 's/:9000/:9072/' /etc/opt/remi/php72/php-fpm.d/www.conf

现在可以在不同的端口上启动两个不同版本的fpm

systemctl start php72-php-fpm
systemctl start php56-php-fpm

使脚本包装程序调用php56-cgi和php72-cgi

make script wrapper to call php56-cgi and php72-cgi

cat > /var/www/cgi-bin/php56.fcgi << EOF
#!/bin/bash
exec /bin/php56-cgi
EOF

cat > /var/www/cgi-bin/php72.fcgi << EOF
#!/bin/bash
exec /bin/php72-cgi
EOF

使它们可由apache执行

sudo chmod 755 /var/www/cgi-bin/php56.fcgi
sudo chmod 755 /var/www/cgi-bin/php72.fcgi

为Apache创建php配置.默认情况下,它运行php56-fcgi处理程序

cat > /etc/httpd/conf.d/php.conf << EOF
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddHandler php56-fcgi .php
Action php56-fcgi /cgi-bin/php56.fcgi
Action php72-fcgi /cgi-bin/php72.fcgi

<Directory /var/www/html/php56>
    DirectoryIndex index.php
    AllowOverride all
    Require all granted
</Directory>
<Directory /var/www/html/php72>
    DirectoryIndex index.php
    AllowOverride all
    Require all granted
</Directory>
EOF

制作测试页,创建.htaccess以使用php72-fcgi

mkdir -p /var/www/html/php56
mkdir -p /var/www/html/php72
echo "<?php phpinfo(); ?>" > /var/www/html/php56/index.php
echo "<?php phpinfo(); ?>" > /var/www/html/php72/index.php
echo "AddHandler php72-fcgi .php" > /var/www/html/php72/.htaccess

现在您应该可以对其进行测试了

( http://127.0.0.1/php56 )
( http://127.0.0.1/php72 )

sudo systemctl enable httpd
sudo systemctl enable php56-php-fpm
sudo systemctl enable php72-php-fpm

这篇关于CentOS 7上使用Apache的多个PHP版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:16