Step 1 — Installing PHP Versions 7.0 and 7.2 with PHP-FPM
Begin by installing the SCL repository to your system:
sudo yum install centos-release-scl -y
First let’s discover what versions of PHP 7 are available on SCL:
sudo yum list rh-php7[0-9].x86_64
You’ll see an output like this:
We will install versions 7.2 and 7.3. Lets begin with the older version. Install rh-php72
and rh-php72-php-fpm
sudo yum install rh-php72 rh-php7-php-fpm -y
rh-php72
is a metapackage that runs PHP applications.rh-php72-php-fpm
provides the Fast Process Manager interpreter that runs as a daemon and receives Fast/CGI requests.
You also can install extensions by using command:
sudo yum install rh-php72 rh-php72-php-fpm rh-php72-php-cli rh-php72-php-common rh-php72-php-gd rh-php72-php-intl rh-php72-php-mbstring rh-php72-php-mcrypt rh-php72-php-mysqlnd rh-php72-php-pdo rh-php72-php-process rh-php72-php-xml -y
Now repeat the process for PHP version 7.3. Install rh-php73
and rh-php73-php-fpm
. Or:
sudo yum install rh-php73 rh-php73-php-fpm rh-php73-php-cli rh-php73-php-common rh-php73-php-gd rh-php73-php-intl rh-php73-php-mbstring rh-php73-php-mcrypt rh-php73-php-mysqlnd rh-php73-php-pdo rh-php73-php-process rh-php73-php-xml -y
Next, run the following commands to start using both software collections:
sudo scl enable rh-php72 bash sudo scl enable rh-php73 bash
By default, both PHP versions are listening on port 9000
. But in this tutorial, we want to run two versions simultaneously. Therefore, let’s designate two new ports:
To accomplish this, you can open /etc/opt/rh/rh-php72/php-fpm.d/www.conf
in your favorite text editor and change every appearance of 9000
to 9002
. Then save and close the file and repeat the process for /etc/opt/rh/rh-php73/php-fpm.d/www.conf
, only now substitute 9000
with 9003
.
Now you are ready to start and enable your PHP services. Begin with your rh-php72-php-fpm
service and enable it to start at boot:
sudo systemctl start rh-php72-php-fpm sudo systemctl enable rh-php72-php-fpm
Next, verify the status of your rh-php72-php-fpm
service:
sudo systemctl status rh-php72-php-fpm
You’ll see an output like this:
Repeating this process, start the rh-php73-php-fpm
service and enable it to start at boot:
sudo systemctl start rh-php73-php-fpm sudo systemctl enable rh-php73-php-fpm
At this point you have installed two PHP versions on your server.
Step 2 — Configuring Nginx for Your Websites
In this section, you will update your website config to make sure that it’ll use right version of php.
nano /etc/nginx/sites-enabled/your_site.conf
Change your fastcgi_pass point to: 127.0.0.1:9002 -> php72 (or 127.0.0.1:9003 -> php7.3)
Finally, restart the Nginx service to implement your changes:
sudo service nginx restart
ENJOY!!!