This guide assumes you already have PHP 7.X installed and want to install an additional PHP 7.X version. The Remi repo should have already been installed as per the NGINX LEMP Setup guide. These commands can be modified for future versions of PHP.
1. First check the default PHP version that is installed.
2. You should see something similar to the following (if PHP 7.1 is already installed)
PHP 7.1.27 (cli) (built: Mar 6 2019 08:15:53) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.27, Copyright (c) 1999-2018, by Zend Technologies
3. You will need to establish a list of currently installed PHP 7.1 packages, so you can install the PHP 7.X versions.
rpm -qa |grep php71
4. Now we need to add a new additional PHP version. This can be done by specifying the explicit version in the yum install command. NB: Your list of packages may differ to the below). Here, we’re using PHP 7.2 as an example.
yum install php72-php-common php72-php-fpm php72-php-gd php72-php-json php72-php-mbstring php72-php-mysqlnd php72-php-xml php72-php-xmlrpc php72-php-opcache
5. You can search for additional available modules and packages using the following
yum search php72 | more
6. Now this is installed, we need to duplicate the existing PHP configuration to a new folder (use -p to preserve the permissions) – Press “No” to overwriting www.conf:
cp -Rp /etc/opt/remi/php71/php-fpm.d/* /etc/opt/remi/php72/php-fpm.d/
7. Now you’ll need to edit the pool configs within this directory and change the “Listen line” to include _php72
Listen = /var/run/php-fpm-name_fpm.sock becomes Listen = /var/run/php-fpm-name_fpm_php72.sock
8. Now enable and start the php-fpm service:
systemctl enable php72-php-fpm systemctl start php72-php-fpm
9. Update the Nginx site configuration to include the new socket file
10. We now reload/restart the nginx service:
systemctl restart nginx
That should be it. You should now have both PHP versions you wish to use installed.
Last modified: 27/11/2019