WordPress 后台的站点健康功能推荐 PHP 版本为 7.4,以便最大限度提高性能和安全性。如果仍在运行旧版本,建议升级。
操作前务必备份数据,以便出错后恢复!
通常情况下,PHP 可以在同一个大版本下无缝平滑升级,如果需要跨大版本更新,则需要卸载原有版本后重新安装新版本。在 OneinStack 环境下,7.2 只能升级 7.2.xx ,不能跨大版本更新。当我的 PHP 升级到 7.4后,输入 7.2.xx 时,同样也会提醒错误。
在理想状态下,用 OneinStack 切换 PHP 大版本是很简单的:
# 进入 oneinstack 目录
cd ~/oneinstack
# 卸载当前版本
./uninstall.sh
# 选择卸载 PHP
# 安装新版本
./install.sh
# PHP 选择 y,其余选择 n
如果真能够顺利安装上,那实在是运气极好。在我的实际操作中,有好几次出现报错,导致升级后网站无法打开。所以在此记录踩过的坑,给读者提供一些经验。
PHP 下载失败
由于发文的时候 PHP 最新版本为 7.4.12,所以本文以这个版本做演示。如果以后出现更新版本,只需到 PHP 官网下载对应版本即可。
在一次尝试升级的过程中,我看到部分 PHP 扩展下载缓慢,但至少能够完成下载,但在下载 PHP 时,最后竟然超时了。这就导致服务器上存在一个不完整的 PHP 源码包,而安装脚本并不会检测源码包的完整性,导致后续编译时出现错误而无法完成安装。
~/oneinstack/src 是存储安装包的目录,如果之前出现过下载失败的问题,需要先删除目录下的不完整包,最好删除所有文件,避免遗漏。
# 进入缓存目录
cd ~/oneinstack/src
# 删除所有文件
rm -rf *
# 从 PHP 官网下载
wget https://www.php.net/distributions/php-7.4.12.tar.gz
# 如果速度太慢,可以通过我的备用链接下载
wget https://www.idcbuy.net/wp-content/uploads/2020/11/php-7.4.12.tar.gz
PHP 源码是整个环节中体积最大也是最容易下载失败的资源,如果能够顺利下载的话就已经离成功不远了。
找不到 oniguruma
在编译的过程中,你可能会看到以下错误信息:
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:
No package 'oniguruma' 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 ONIG_CFLAGS
and ONIG_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
make: *** No targets specified and no makefile found. Stop.
make: *** No rule to make target `install'. Stop.
PHP install failed, Please Contact the author!
oniguruma 是一个处理正则表达式的库,PHP 7.4 中,mbstring 的正则表达式处理功能对这个包有依赖性。所以,安装 PHP 7.4 前需要安装 oniguruma 和 oniguruma-devel 两个软件包。网络小乙 – https://www.jianshu.com/p/cda792d5139f
建议手动下载 RPM 包进行安装:
# 下载 oniguruma5php-6.9.5+rev1-4.el7.remi.x86_64.rpm
wget https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-6.9.5+rev1-4.el7.remi.x86_64.rpm
# 下载 oniguruma5php-devel-6.9.5+rev1-4.el7.remi.x86_64.rpm
wget https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5php-devel-6.9.5+rev1-4.el7.remi.x86_64.rpm
# 安装
rpm -ivh *.rpm
如果上面的地址已经失效,可以访问 https://centos.pkgs.org/7/remi-x86_64/ ,搜索 oniguruma 找到 oniguruma5php 和 oniguruma5php-devel 的 binary package 链接。
oniguruma 安装完成后再安装 PHP 一般就能够顺利编译了。最后可以看到 WordPress 后台站点健康页面的大勾。
本作品采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 进行许可
赏微信打赏
喜欢本文吗?请我喝杯雪碧吧~~