OneinStack 自带 php 升级脚本,不过目前并不支持从 php 7.3.12 升级到 php 7.4.0,不知道以后会不会支持。忍不住手动升级了,折腾前先备份一下。
备份当前版本 php
which php ## 一般是 /usr/local/php/bin/php
cp -r /usr/local/php /usr/local/php_bak
获取当前版本 php 配置参数
执行如下命令:
/usr/local/php/bin/php -i | head
输出配置参数:
phpinfo()
PHP Version => 7.3.12
System => Linux cyhour.com 5.3.11-1.el7.elrepo.x86_64 #1 SMP Tue Nov 12 14:45:59 EST 2019 x86_64
Build Date => Nov 28 2019 15:03:18
Configure Command => './configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/php.d' '--with-fpm-user=www' '--with-fpm-group=www' '--enable-fpm' '--enable-opcache' '--disable-fileinfo' '--enable-mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir=/usr/local' '--with-freetype-dir' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl=/usr/local/curl' '--enable-mbregex' '--enable-mbstring' '--with-password-argon2' '--with-sodium=/usr/local' '--with-gd' '--with-openssl=/usr/local/openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-ftp' '--enable-intl' '--with-xsl' '--with-gettext' '--enable-zip' '--without-libzip' '--enable-soap' '--disable-debug'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => /usr/local/php/etc/php.ini
./configure 后面就是需要的参数:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --with-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug
要注意,php 7.4.0 已经不支持 --with-gd,得改成 --enable-gd,否则会报错「GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library」。另外还有这几个参数也有变动:configure: WARNING: unrecognized options: --with-freetype-dir, --with-jpeg-dir, --with-png-dir, --with-libxml-dir, --enable-zip, --without-libzip
修改后参数:
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype --with-jpeg --with-zlib --with-libxml --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug
下载 PHP
从 https://www.php.net/downloads.php 页面下载最新 php Stable 版本,解压,进入源码目录。
wget https://www.php.net/distributions/php-7.4.0.tar.gz
tar xf php-7.4.0.tar.gz
cd php-7.4.0
配置 php
编译前,进入源代码目录,configure 脚本配置。
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/php.d --with-fpm-user=www --with-fpm-group=www --enable-fpm --enable-opcache --disable-fileinfo --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir=/usr/local --with-freetype --with-jpeg --with-zlib --with-libxml --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd --with-openssl=/usr/local/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-ftp --enable-intl --with-xsl --with-gettext --enable-zip --without-libzip --enable-soap --disable-debug
可能会报错:No package 'sqlite3' found,解决方法:
yum install libsqlite3x-devel -y
报错:No package 'oniguruma' found,解决方法:
yum install oniguruma-devel -y
实际配置中还出现了:No package 'libsodium' found 错误,重新安装 libsodium,错误依旧。解决方法:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH
或者直接把用不到的 --with-sodium=/usr/local 去掉。
配置成功:
Generating files
configure: patching main/php_config.h.in
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/www.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
+--------------------------------------------------------------------+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
Thank you for using PHP.
configure: WARNING: unrecognized options: --enable-zip, --without-libzip
编译 PHP
./configure 配置通过,使用 make 直接编译,会报错:
collect2: ld returned 1 exit status make: *** [sapi/cli/php] Error 1
加上 ZEND_EXTRA_LIBS='-liconv' 即可:
make ZEND_EXTRA_LIBS='-liconv'
安装 PHP
编译成功,先停止 php-fpm 服务:
systemctl stop php-fpm
安装:
make install
安装成功,启动 php-fpm 服务:
systemctl start php-fpm
重新安装上 Memcached
如果原本开启了 Memcached,可能需要重新安装一下,否则网站 500……OneinStack 安装 php-memcached 扩展:
cd /root/oneinstack
./install.sh --php_extensions memcached
参考资料
折腾挺累的,还是一键脚本升级方便啊。
--- 完 ---
还是习惯面板操作。。。。。宝塔,我离不了了。
@张波博客 宝塔我试用过几次,确实很方便。
PHP7.4 有啥特性
@灰常记忆 放狗就能找到啊,我纯粹是忍不住升级,什么新特性我还不知道怎么用上……
@老头 你不是升级了
@灰常记忆 是升级了啊,但是不知道有没有用上新特性啊,囧?……
@老头 ?看见新版就直接升级
@灰常记忆 新版本出来有些时间了,并不能一键升级……测试了几次才敢升级的啊。
升级了有什么感受。
@奶爸建网站笔记 最大的感受是:还好,升级成功,不用重新搭建环境。
oneinstack 那个升级脚本一直只能在小版本内更新,不能跨大版本,不过好像更新也很简单,直接删除再用 Oneinstack 重装一次 PHP 7.4 就好,其他不用安装,理论上是行得通的。
@TZH 也是个方法,下次有需要试试。现在以及按文中方法折腾升级上去了。