Hamsa K
Editor
6 min read | 3 years ago

How to Install Multiple PHP Versions with Apache on Centos 7

Installing multiple php versions on Centos 7

PHP is a general-purpose scripting language especially suited to web development.To install multiple versions of PHP, you will need to install and enable the Remi repository to your system.

This tutorial help you on how to install multiple php versions with apache on centos 7 system.

First we will install epel repo and install apache with the following commands.

yum instal epel-release
yum install httpd

Also Read -> How to Install PHP 8 on Ubuntu 20 04

once apache is installed,we are going to install remi repository and then install php 5.6 and 7.4 versions.

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils 
yum install php56 
yum install php74 
yum install php56-php-fpm 
yum install php74-php-fpm 

By default it listens on 127.0.0.1 port 9000.so we will make them listen on diffrent ports as below.

 vi /etc/opt/remi/php56/php-fpm.d/www.conf

change the port 9000 to any other port like 9056 and save the file.

vi /etc/opt/remi/php74/php-fpm.d/www.conf

change the port 9000 to any other port like 9074 and save the file.

Now you can start the php-fpm services on diffrent ports.

systemctl start php56-php-fpm
systemctl start php74-php-fpm

now you can make the script wrapper to call php56-cgi and php74-cgi

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

then, set executable permissions to the files.

chmod 755 /var/www/cgi-bin/php56.fcgi
chmod 755 /var/www/cgi-bin/php74.fcgi

Now create php configuration for apache.by default it runs php56-fcgi handler.

vi /etc/httpd/conf.d/php.conf

Add below content to above file.

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
AddHandler php56-fcgi .php
Action php56-fcgi /cgi-bin/php56.fcgi
Action php74-fcgi /cgi-bin/php74.fcgi
<Directory /var/www/html/php56>
    DirectoryIndex index.php
    AllowOverride all
    Require all granted
</Directory>
<Directory /var/www/html/php74>
    DirectoryIndex index.php
    AllowOverride all
    Require all granted
</Directory>

save and exit the file.

now you can create test pages with the following commands.

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

and also create .htaccess to use php74-fcgi

Also Read -> How to Install PHP 8 on Centos 8

echo "AddHandler php74-fcgi .php" > /var/www/html/php74/.htaccess

now you can restart and enable the services

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

then you can test both the urls like below.

http://ip_address/php56

http://ip_address/php74

That's it.Now you have successfully installed different versions of php on centos 7 server.

Also Read -> How to Install php 8 on Debian 10



Warning! This site uses cookies
By continuing to browse the site, you are agreeing to our use of cookies. Read our terms and privacy policy