Ubuntu Configure Nginx with Multiple PHP Versions

1- Install Nginx to install nginx
sudo apt update
sudo apt install nginx
make sure that you dont have anything running on port 80, otherwise you will need to either configure nginx to another port b4 running or disable any active app server running on port 80 to disable apache2 for example
sudo systemctl disable apache2
enable nginx to be started automatically
sudo systemctl enable nginx
start nginx and check its status
sudo systemctl start nginx
systemctl status nginx
if status shows that nginx is running then your good to go

2- Install PHP Versions

the defualt version of php is always the newest and you can install it by running the below command:
sudo apt-get install php php-fpm
for older versions you can get it from: A: old version rebositoy to add and install using apt-get
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6 php5.6-fpm
B: install fro source downloaded from php.net archive "google it (:"

3- Configure Hosts for each php version
sudo nano /etc/hosts
add multiple hosts each one will point to a version of php, below is a example

4- Configure PHP-FPM for each version open the config file for fpm
for php 7.1 it would be
now find the line where it has
listen = /run/php/php{php-version}-fpm.sock
comment it out by a hash and enter this line below
listen =
Note: the ip address must match the /etc/hosts input you did earlier for the desired host now do the same to all php version you want to run and keep note of all the input, at the end you should have a list of php-fpms addreses like this for example:
listen = for php 7.1 | matching host php-7-1.co
listen = for php 7.0 | matching host php-7-0.co
listen = for php 5.6 | matching host php-5-6.co
listen = for php 4.6 | matching host php-4-6.co

5- Configure Nginx
sudo nano /etc/nginx/sites-available/default
- uncomment the block that start with:
location ~ \.php$ {
- comment out the line that start with:
fastcgi_pass unix:/var/run/php/;
- un comment or add this line inside "location ~ \.php$"
- copy and past the server{} code for as many as php version you have - change each server block config following detail to match your php-fpm and host config
- listen {ip}:{port} default_server
- server_name {ip} {domain}
- fastcgi_pass {ip}:{port}

6- Restart All Services
sudo systemctl restart nginx
sudo systemctl restart php{vrsion}-fpm ( repeat for all versions)



  1. PHP is a server side scripting language and most of the developer choice is PHP nowadays, since it is highly secure. Your blog on PHP secureness is unique from other. I hope your content was read by most of the people in the World Wide Web.
    PHP Institutes in Chennai
    PHP Training Center in Chennai

  2. Excellent blog on Web technology!!! Have gained more information related to website development. Thank admin for this wonderful content.
    web development courses in chennai with placement
    Web designing training centers in chennai

  3. A good blog always comes-up with new and exciting information and while reading I have feel that this blog is really have all those quality that qualify a blog to be a one.I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts read this.

    click here

    Selenium Training in Bangalore|
    Selenium Training in Chennai


Post a Comment

Popular Posts