Sponsored

Not the solution you were looking for?

We’ll help you out!

Run multiple versions of PHP for different domains in NGNIX

I recently purchased EduExpression WordPress plugin for a client to setup an examination software. I was able to install and configure the plugin without much problem. However, the problem started occurring when the student login was accessed – the plugin page went blank when the student attempted to take an exam. Well, I have a support right? I contacted the support team and they said, the plugin does not work with PHP 7.1 and it only supports PHP 5.6. That’s my bad – because I had my server setup with PHP 7.1 and all of my client website’s running on PHP 7.1. Now to make EduExpression to work, I need to setup PHP 5.6 version. Downgrading PHP is never a good option, but I had to do this to make this plugin work for the client. So how about setting up PHP 5.6 only for a particular domain and leave the rest to run on PHP 7.1. Well, in this tutorial I’ll explain how to setup multiple versions of PHP environment and link specific version of PHP with a particular domain in NGINX.

Configure PHP-FPM and PHP56-PHP-FPM

Most important part of the this tutorial is to configure two different PHP-FPM for two PHP versions. Here we shall configure two different versions of PHP-FPM that Nginx will work with. The main thing during configuration is the user/group of FastCGI processes and the ports they listen on.

PHP-FPM (Default 7.1) configuration file

/etc/php-fpm.d/www.conf

Make sure user/group set to nginx (Default value is apache).

user = nginx
group = nginx

Find the listen parameter and set it to port 9000 on which FastCGI requests will be received.

listen = 127.0.0.1:9000 [php-fpm]

PHp56-PHP-FPM configuration file

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

Make sure user/group set nginx (Default value is apache).

user = nginx
group = nginx

Find the listen parameter and set it to port 9001 on which FastCGI requests will be received.

listen = 127.0.0.1:9001 [php56-php-fpm]

Enable PHP-FPM, PHP56-PHP-FPM and NGINX auto start at system boot on CentOS 7

After completing the above configurations, you need to enable the PHP-FPM, PHP56-PHP-FPM and Nginx to auto start at system boot.