阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Ubuntu 16.04环境LNMP实现 PHP5.6和PHP7.2多版本共存

153次阅读
没有评论

共计 1890 个字符,预计需要花费 5 分钟才能阅读完成。

Linux 操作系统:Ubuntu 16.04

因为公司项目跑 PHP5.6,而自己学习需要 PHP7.2, 所以需要这两个版本共存。

LNMP 的搭建,首先搭建的是 5.6 的版本,不影响,在此基础上再安装一个 PHP7.2。

PPA 方式安装 php7.2 :
sudo apt-get install software-properties-common
 
添加 php7 的 PPA
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
更新安装包
sudo apt-get update
检验是否安装成功, 运行命令如若成功就能开始安装 php7.2
 
apt-cache search php7.2

php7.2 安装
 
sudo apt-get -y install php7.2
 
apt-get install php7.2-dev

运行 php - v 查看版本, 出现版本结果即为成功

安装 PHP7.2 的各个模块

 sudo apt-get -y install php7.2-MySQL
 
sudo apt-get install php7.2-fpm
 
apt-get install php7.2-curl php7.2-xml php7.2-json php7.2-gd php7.2-mbstring

修改 PHP-FPM 的配置

vim /etc/php/7.2/fpm/php-fpm.conf 或者 /etc/php/7.2/fpm/pool.d/ 下配置文件
 
pm.max_children = 5    =>    pm.max_children = 20  最大子进程数
 
listen = /run/php/php7.2-fpm.sock    =>    listen = 127.0.0.1:9001
 
重启:service php7.2-fpm restart
因为之前安装的 PHP5.6 下配置文件中

listen = /run/php/php5.6-fpm.sock  => 127.0.0.1:9000
 
本地 9000 端口被 5.6 版本使用, 所以这里 7.2 版本使用 9001 端口(关键!!!: 两个版本共存监听不一样的端口)

同时在 PHP7.2 项目的 nginx 配置文件中

location ~ \.php$ {
 
    fastcgi_pass  127.0.0.1:9001; // 这里要改成刚刚修改的端口
 
    fastcgi_index  index.php;
 
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
 
    include        fastcgi_params;
 
}

重启 nginx 和 php-fpm 之后, 两个不同版本的项目可同时运行

systemctl restart nginx;
systemctl restart php7.2-fpm;

Red Hat Enterprise Linux 7.3 下 PHP 安装  https://www.linuxidc.com/Linux/2017-05/143942.htm
《细说 PHP》高清扫描 PDF+ 光盘源码 + 全套教学视频 https://www.linuxidc.com/Linux/2014-03/97536.htm
CentOS 7.3 环境下 PHP7.0 安装  https://www.linuxidc.com/Linux/2017-08/146433.htm
CentOS 7.2 下编译安装 PHP7.0.10+MySQL5.7.14+Nginx1.10.1  https://www.linuxidc.com/Linux/2016-09/134804.htm
Linux 安装 PHP5 与 PHP7 共存  https://www.linuxidc.com/Linux/2018-01/150007.htm
Linux 安装 PHP 扩展模块详解  https://www.linuxidc.com/Linux/2018-01/150006.htm
CentOS 7 下 PHP 7.1.12 安装配置  https://www.linuxidc.com/Linux/2018-01/150508.htm
CentOS 7 下使用 MySQL 5.7 + PHP 7 + Apache 部署 Nextcloud  https://www.linuxidc.com/Linux/2017-12/149945.htm
Ubuntu 17.10 上安装 LEMP 环境(Nginx,MariaDB,PHP7.1)https://www.linuxidc.com/Linux/2017-12/149581.htm

PHP 的详细介绍:请点这里
PHP 的下载地址:请点这里 

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计1890字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中