How to run multiple websites with mix of php 5 and php 7 on Ubuntu 16 Nginx 64bit on a single droplet?

September 3, 2016 248 views
Nginx PHP Ubuntu 16.04

I have already setup multiple websites on 64bit Ubuntu 16 Nginx server with php 7
Now I'd like to add another website to the same droplet to use php 5, (this premade site need ionCube loader, ionCube doesn't support php7) Please help

1 Answer

For adding multiple sites on nginx server you should utilize Nginx Server Blocks (Virtual Hosts). More about Nginx Server Blocks you can read in this DigitalOcean tutorial.

The main idea is to have one VH to point on php-5, while another will point to php-7.
This could be done by setting correct php path under ~.php$ location in Server Block config file.
Taken from Ubuntu 14.04 LEMP tutorial your php config should be something like...

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;

For php-7 we will reefer to Ubuntu 16.04 LEMP tutorial, here it should look like

   location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;

For full guide reefer to links I given you, they're pretty good-written tutorials. :)
I hope this will fix problem

by Justin Ellingwood
A LEMP stack (Linux, Nginx, MySQL, and PHP) is a powerful set of software that can be configured to serve dynamic sites and web apps from your server. In this guide, we will discuss how to install a LEMP stack on an Ubuntu 14.04 server.
Have another answer? Share your knowledge.