nginx配合两个或多个PHP版本。php5.6与php7

首先感谢这篇文章:Mac 下 Nginx、PHP、MySQL 和 PHP-fpm 的安装和配置

由于我的PHP7是通过brew安装的。

brew安装的东西都在目录/usr/local/opt/  下了。这是我知识的盲点。所以找了很久没找到。

看到这篇文章后,到了/usr/local/opt/php71/sbin/ 目录下果然看到了php-fpm

接下来的事情很容易了

sudo ln -s /usr/local/opt/php71/sbin/php-fpm /usr/sbin/php-fpm  将它软连接过去,

没有使用cp ,因为/usr/sbin/已经有个5.6了,我想以后可以做切换使用。

有人说mac不支持 多个PHP版本切换,我证明了,是可以的。

实现配置2个版本PHP,

修改php7的php-fmp服务端口号

进入到目录:/usr/local/etc/php/php7.1/php-fpm.d/www.conf

修改 www.conf这个文件的监听端口listen = 127.0.0.1:9009

可以了。

现在的情况是:

PHP5.6的php-fpm监听的是 127.0.0.1:9000

PHP7.1的php-fpm监听的是 127.0.0.1:9009

有了这两个那就可以在nginx上干活了

进入nginx配置目录

/usr/local/etc/nginx/nginx.conf

一下是nginx配置:(注意看两个server 的 fastcgi_pass:后面监听的端口)

9987-> 127.0.0.1:9000 ->PHP5.6

9988-> 127.0.0.1:9009 ->PHP7.1

server {

        listen       9987;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root   /Volumes/data/DockerTools/code/advanced_dev/frontend/web;

            index  index.php,index.html index.htm;

            try_files $uri $uri/ /index.php?$args;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page   500 502 503 504  /50x.html;

        #location = /50x.html {

        #    root   html;

        #}

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           /Volumes/data/DockerTools/code/advanced_dev/frontend/web;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    server {

        listen 9988;

        server_name  boo.local.anlewo.com;

        #access_log  /log/frontend.local.anlewo.access.log  main;

        location / {

            root   /Volumes/data/DockerTools/code/advanced_dev/frontend/web;

            index  index.php index.html index.htm;

            try_files $uri $uri/ /index.php?$args;

        }

        location ~ \.php$ {

            root           /Volumes/data/DockerTools/code/advanced_dev/frontend/web;

            fastcgi_pass   127.0.0.1:9009;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

    }

截图认证:

 

原文https://www.jianshu.com/p/49fbc8d918db

 

注意

在nginx vhost配置中为项目配置响应的php版本

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值