2021-11-25,PHP 8.1 正式版发布,相对于 PHP 8.0,WordPress 有 3.5% 性能提升。休息时间尝试 OneinStack 将 php 8.0.12 升级到 php 8.1.3。
OneinStack php 升级
OneinStack 自带 php 升级脚本,不过并不支持跨版本升级,比如只能从 php 8.0.6 升级到 php 8.0.17,而无法从 php 8.0.16 升级到 php 8.1.3。
「OneinStack 将 php 8.0.12 升级到 php 8.1.3:https://ae.mba/25」OneinStack php 8.0.16 升级到 php 8.1.3, 需要手工折腾编译升级。
温馨提示:运行环境不可能完全一样,教程不一定都能成功,折腾前先备份一下!最好是做个快照(Snapshot),出问题恢复即可。
以下实战环境:Vultr VPS,1G+2G swap,CentOS Stream release 8
「OneinStack 将 php 8.0.12 升级到 php 8.1.3:https://ae.mba/25」备份当前版本 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 => 8.0.12
System => Linux ae.mba 5.16.15-1.el8.elrepo.x86_64 #1 SMP PREEMPT Tue Mar 15 10:45:43 EDT 2022 x86_64
Build Date => Nov 18 2021 22:07:10
Build System => Linux ae.mba 4.18.0-348.el8.x86_64 #1 SMP Tue Oct 19 15:14:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
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' '--with-freetype' '--with-jpeg' '--with-zlib' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--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' '--enable-ftp' '--enable-intl' '--with-xsl' '--with-gettext' '--with-zip=/usr/local' '--enable-soap' '--disable-debug' 'PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:'
Server API => Command Line Interface
Virtual Directory Support => disabled
Configuration File (php.ini) Path => /usr/local/php/etc
./configure 后面就是需要的参数:
「OneinStack 将 php 8.0.12 升级到 php 8.1.3:https://ae.mba/25」./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 --with-freetype --with-jpeg --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --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 --enable-ftp --enable-intl --with-xsl --with-gettext --with-zip=/usr/local --enable-soap --disable-debug PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:
下载 PHP
从 https://www.php.net/downloads.php 页面下载最新 php Stable 版本,解压,进入源码目录。
wget https://www.php.net/distributions/php-8.1.3.tar.gz
tar xf php-8.1.3.tar.gz
cd php-8.1.3
配置 php
编译前,进入源代码目录(如:/root/oneinstack/src/php-8.1.3),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 --with-freetype --with-jpeg --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --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 --enable-ftp --enable-intl --with-xsl --with-gettext --with-zip=/usr/local --enable-soap --disable-debug PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:
configure: error: Package requirements (libargon2) were not met:
可能报错:configure: error: Package requirements (libargon2) were not met:
「OneinStack 将 php 8.0.12 升级到 php 8.1.3:https://ae.mba/25」checking whether arc4random_buf is declared... no
checking for Argon2 support... yes
checking for libargon2... no
configure: error: Package requirements (libargon2) were not met:
Package 'libargon2', required by 'virtual:world', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables ARGON2_CFLAGS
and ARGON2_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
另外如果提示 *** cannot find -largon2,(也可能是类似 Please verify that Argon2 header and libraries >= 20161029 are installed 错误提示)解决方法也是安装 Argon2 即可:
sudo yum install -y libargon2 libargon2-devel
安装完再进入 php-8.1.3 源码目录执行前面的 ./configure 进行配置.
php ./configure 配置成功
…………………
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
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.
make 编译 PHP
./configure 配置通过,使用 make 直接编译。
make
编译成功:
…………………
/bin/sh /root/oneinstack/src/php-8.1.3/libtool --silent --preserve-dup-deps --tag CC --mode=link cc -export-dynamic -fno-common -Wstrict-prototypes -Wformat-truncation -Wlogical-op -Wduplicated-cond -Wno-clobbered -Wall -Wextra -Wno-strict-aliasing -Wno-unused-parameter -Wno-sign-compare -g -O2 -fvisibility=hidden -Wimplicit-fallthrough=1 -DZEND_SIGNALS …… -ljpeg -lfreetype -licuio -licui18n -licuuc -licudata -lonig -lsqlite3 -lxml2 -lxml2 -lsodium -largon2 -lrt -ldl -lxml2 -lxml2 -lxml2 -lxslt -lm -lxml2 -lexslt -lxslt -lm -lgcrypt -ldl -lgpg-error -lxml2 -lzip -lz -lz -lssl -lcrypto -lcrypt -o sapi/cgi/php-cgi
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
pharcommand.inc
directorygraphiterator.inc
phar.inc
invertedregexiterator.inc
clicommand.inc
Build complete.
Don't forget to run 'make test'.
安装 PHP
编译成功,先停止 php-fpm 服务:
systemctl stop php-fpm
安装:
make install
日志:
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20210902/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM defconfig: skipping
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
/root/oneinstack/src/php-8.1.3/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin/phar.phar
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/
安装成功,启动 php-fpm 服务:
systemctl start php-fpm
执行 php -v 可检查 php 版本:
PHP 8.1.3 (cli) (built: Mar 17 2022 21:03:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.3, Copyright (c) Zend Technologies
with Zend OPcache v8.1.3, Copyright (c), by Zend Technologies
如无意外,此时网站也能正常访问。
重新安装上 Memcached
如果原本开启了 Memcached,可能需要重新安装一下,否则访问网站报错:「此站点遇到了致命错误。了解有关对 WordPress 进行故障排除的更多信息。」
OneinStack 安装 php-memcached 扩展:
cd /root/oneinstack
./install.sh --php_extensions memcached
Memcached 安装完成,网站也恢复正常访问。
开启 Opcache JIT
不管有用没用,jit 也开上吧,在 opcache 配置中加入两行代码即可:
opcache.jit_buffer_size=128M
opcache.jit=1255
Opcache 参考配置:
[opcache]
zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=128M
opcache.jit=1255
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=100000
opcache.max_wasted_percentage=5
opcache.use_cwd=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
;opcache.save_comments=0
opcache.fast_shutdown=1
opcache.consistency_checks=0
;opcache.optimization_level=0
opcache.huge_code_pages=1
温馨提示:OneinStack Opcache 配置文件路径为:/usr/local/php/etc/php.d/02-opcache.ini
--- 完 ---
解压及网盘密码 1024
Comments:0