此前是将 php 8.0.12 升级到 php 8.1.3,不过目前 WordPress 看起来还没有完全适配 php 8.1 和 php 8.2,于是尝试折腾降级 php 版本。
OneinStack php 降级
OneinStack 自带 php 升级脚本,不过好像没有降级脚本,就算有应该也不支持跨版本降级,比如只能从 php 8.0.28 降级到 php 8.0.17,而无法从 php 8.2.4 降级到 php 8.0.28。
「OneinStack 将 php 8.2.4 降级到 php 8.0.28:https://ae.mba/72」OneinStack php 8.2.4 降级到 php 8.0.28, 需要手工折腾编译降级。
温馨提示:运行环境不可能完全一样,教程不一定都能成功,折腾前先备份一下!最好是做个快照(Snapshot),出问题恢复即可。
备份当前版本 php
which php ## 一般是 /usr/local/php/bin/php
cp -r /usr/local/php /usr/local/php_bak
获取当前版本 php 配置参数
执行如下命令:
「OneinStack 将 php 8.2.4 降级到 php 8.0.28:https://ae.mba/72」/usr/local/php/bin/php -i | head
输出配置参数:
phpinfo()
PHP Version => 8.2.4
System => Linux valuable-gigs-3.localdomain 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) x86_64
Build Date => Mar 31 2023 08:25:33
Build System => Linux valuable-gigs-3.localdomain 5.10.0-8-amd64 #1 SMP Debian 5.10.46-4 (2021-08-03) 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=/usr/local' '--with-freetype' '--with-jpeg' '--with-zlib' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-exif' '--enable-sysvsem' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-password-argon2' '--with-sodium=/usr/local' '--enable-gd' '--with-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 后面就是需要的参数:
./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=/usr/local --with-freetype --with-jpeg --with-zlib --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --with-curl --enable-mbregex --enable-mbstring --with-password-argon2 --with-sodium=/usr/local --enable-gd --with-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 版本,解压,进入源码目录。
「OneinStack 将 php 8.2.4 降级到 php 8.0.28:https://ae.mba/72」wget https://www.php.net/distributions/php-8.0.28.tar.gz
tar xf php-8.0.28.tar.gz
cd php-8.0.28
配置 php
编译前,进入源代码目录(如:/root/oneinstack/src/php-8.0.28),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/:
php ./configure 配置成功
(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 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
编译成功:
「OneinStack 将 php 8.2.4 降级到 php 8.0.28:https://ae.mba/72」/usr/bin/ld: warning: libicuuc.so.67, needed by /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/libxml2.so, may conflict with libicuuc.so.63
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
invertedregexiterator.inc
directorygraphiterator.inc
directorytreeiterator.inc
pharcommand.inc
clicommand.inc
phar.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-20200930/
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.0.28/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.0.28 (cli) (built: Mar 31 2023 10:50:20) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.28, Copyright (c) Zend Technologies
with Zend OPcache v8.0.28, 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