php7.1 ,7.2 多版本共存,同一台电脑不同项目使用不通PHP版本

/usr/local/php/sbin/php-fpm -v #启动 php7.1

注意:

1 . 关闭这个应用文件  include enable-php.conf
2. 对于这个项目,使用你的   unix:/tmp/php72-cgi.sock

3. 重启 nginx :

service nginx restart    #reload 不生效

geekpanda.conf

server
    {
        listen 80 ;
        #listen [::]:80 default_server ipv6only=on;
        server_name geekpandalocal.com  www.geekpandalocal.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/default/newproject/uugeekpandashare;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        #include enable-php.conf; #1 . 关闭这个应用文件

        location /nginx_status
        {
            stub_status on;
            access_log   off;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location / {
            if (!-e $request_filename){
                rewrite ^/(.*)$ /index.php?s=/$1 last;
            }
        }
         location ~ /\.
        {
          deny all;
        }

	 #2. 对于这个项目,使用php7.2
          location ~ [^/]\.php(/|$) {
                try_files $uri =404;
                fastcgi_pass  unix:/tmp/php72-cgi.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
              }

        access_log  /home/wwwlogs/access.log;
    }

server
    {
        listen 80 ;
        #listen [::]:80 default_server ipv6only=on;
        server_name api.geekpandalocal.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/default/newproject/uugeekpandashare;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;

        location /nginx_status
        {
            stub_status on;
            access_log   off;

        }

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location / {
            if (!-e $request_filename){
                rewrite ^/(.*)$ /index.php?s=/$1 last;
            }
        }
                location ~ /\.
        {
          deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }

================以下是参考===========

:安装

下载不同版本的PHP源码到服务器上,在编译安装时为不同的版本指定不同的路径,例如:

--prefix=/usr/local/php5.6 //指定PHP5.6版本的安装路径
--prefix=/usr/local/php7.2.3 //指定PHP7.2版本的安装路径

本地执行脚本指定PHP版本

安装好之后,如果需要在服务器端执行PHP脚本,假设已进入脚本的路径下,为test.php。使用不同版本PHP执行PHP文件的命令如下:

/usr/local/php5.6/bin/php test.php      //使用PHP5.6执行脚本
/usr/local/php7.2.3 test.php            //使用PHP7.2.3执行脚本
  • 也可以修改/etc/profile文件中的PATH环境变量,将需要的版本的PHP的bin目录加到环境变量中,这样,只要在任何路径下调用PHP,使用的都是在环境变量中设置的版本了。环境变量配置示例如下:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/php5.6/bin"
  • 指定浏览器访问时执行的PHP版本

先执行命令ps aux | grep php查看当前是否有php-fpm正在运行,如果有,将之关闭。
然后执行命令/usr/local/php5.6/sbin/php-fpm启动5.6版本的php-fpm,这样,前端访问服务器时,所有的脚本将由php5.6进行解释执行。

这样就实现了PHP多个版本的切换。

不过两个不同的php版本是通过编译安装的话,很容易出问题,因为他们倚赖的库的版本可能不一样,这样可能需要安装不同依赖版本的库就可以解决,有时间折腾可以尝试。

参考: php-fpm报502问题

 分享一下php7和其他php多版本共存的配置教程

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lxw1844912514

你的打赏就是对我最大的鼓励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值