Hamid Ghorashi
Hamid Ghorashi

Reputation: 1001

Using two different php versions on the same machine

I'm using ubuntu 16.0.4 having nginx and php7.0-fpm installed on it. Is it possible to use another version of php for another project at the same time?

How should I change my nginx config file?

Upvotes: 0

Views: 1257

Answers (3)

jtza8
jtza8

Reputation: 11

It might be a good idea to consider using Docker for this. Even if it is possible to have multiple versions of PHP on the same server.

Docker is an elegant system which allows you to run multiple instances of operating systems at the same time without the drawbacks of virtual machines.

Why run multiple operating systems? If you have a situation where you need to have a certain version of PHP for one project and another version for another project, then you could create two Docker "containers" which would be two separate Ubuntu environments where nginx can be configured to work for each project separately.

The main advantage is that there is no possibility of breaking one project while working on the other. You can safely customise your nginx server for whatever bazaar requirements any project might have. You can also copy a container so that multiple people can all work with exactly the same Ubuntu environment with the same versions and configuration files for everything.

It might sound inefficient, but its not:

  • A container (Ubuntu environment) is typically about 200MB big since you only need to install what you are going to use for that project.
  • Docker is a Hypervisor which means its not faking hardware like a virtual machine, instead it uses your machine's hardware directly.
  • The kernel is shared when you run Docker in Linux. This means all the executable binaries in the containers are run exactly like native binaries but in different environments.

Upvotes: 1

Andrea Golin
Andrea Golin

Reputation: 3559

I usualy change the fastcgi_pass socket variable into my nginx conf file.

 location ~ \.php$ {
       ...

        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

       ....
    }

Check the sock location for your php version. Mine (using Debian 9) can be located into /var/run/php/

cd /var/run/php

I currently have both php fpm 5.6 and 7.2 installed on my system, and the list command will output both php5.6-fpm.sock and php7.2-fpm.sock files.

You could then substitute the sock pointer into the nginx file:

location ~ \.php$ {
    ...
    fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
    ....
}

Remember to reload nginx afterwards:

sudo systemctl restart nginx

Upvotes: 0

gzhh
gzhh

Reputation: 1

Maybe you could try to use Docker or Vagrant. Or try this: https://tecadmin.net/install-multiple-php-version-nginx-ubuntu/

Upvotes: 0

Related Questions