如果是在一台新机器上安装 PHP 7.2 , 请参考文章在 Ubuntu 14.04 上搭建 LNMP 环境,只需将其中 PHP 编译安装的部分按照本文中的部分替换PHP版本即可。
此次因为是升级,所以 PHP 编译安装所需的扩展应用等早已安装,只需要重新编译安装 PHP7.2 及相关 PHP 扩展,再关停原来的 php-fpm 并开启 7.2 版本的 php-fpm,然后将 Nginx 的代理解析监听到 PHP 7.2 的 php-fpm 上即可。
1、下载PHP源码并编译安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| ./configure \ --prefix=/usr/local/php72 \ --with-config-file-path=/usr/local/php72/etc \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-soap \ --enable-calendar \ --with-curl \ --with-mcrypt \ --with-zlib \ --with-gd \ --disable-rpath \ --enable-inline-optimization \ --with-bz2 \ --with-zlib \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-pcntl \ --enable-mbregex \ --enable-exif \ --enable-bcmath \ --with-mhash \ --enable-zip \ --with-pcre-regex \ --with-pdo-mysql \ --with-mysqli \ --with-mysql-sock=/var/run/mysqld/mysqld.sock \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --enable-gd-native-ttf \ --with-openssl \ --with-fpm-user=www-data \ --with-fpm-group=www-data \ --enable-ftp \ --with-imap \ --with-imap-ssl \ --with-kerberos \ --with-gettext \ --with-xmlrpc \ --with-xsl \ --enable-opcache \ --enable-fpm
make && sudo make install
|
2、安装redis/memcache扩展
前文介绍过的扩展 git 仓库已升级,都不再需要切换到 php7 分支,直接使用 master 分支安装即可。
3、编译安装其他需要的PHP扩展(php-ext-trie-filter)
参考前文 PHP 敏感词过滤
4、修改Nginx配置文件
主要将各站点 conf 文件中对PHP的监听作如下修改:
1 2
| fastcgi_pass unix:/var/run/php7-fpm.sock; // Old fastcgi_pass unix:/var/run/php72-fpm.sock; // New
|
5、停用crontab
6、停用PHP_FPM,启用新版
7、重启Nginx
重启Nginx失败遇到权限问题可尝试如下修改
1 2
| # nginx.conf user=www-data
|
8、重启crontab【修改PHP执行路径