2018-10-08 08:39



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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dousongqiang2585 dousongqiang2585 3年前

    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
    点赞 评论 复制链接分享
  • duanjue9296 duanjue9296 3年前

    Maybe you could try to use Docker or Vagrant. Or try this:

    点赞 评论 复制链接分享
  • dongnue2071 dongnue2071 3年前

    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.
    点赞 评论 复制链接分享