最近想把自己wp博客的php版本升级下,结果升级的并不是很顺利,特此记录一下
升级PHP版本
因本博客使用lnmp一键安装包安装的,所以利用如下命令升级php版本:
cd /root/lnmp1.7
./upgrade.sh php
提示如下:
+-----------------------------------------------------------------------+
| Upgrade script for LNMP V1.6, Written by Licess |
+-----------------------------------------------------------------------+
| A tool to upgrade Nginx,MySQL/Mariadb,PHP for LNMP/LNMPA/LAMP |
+-----------------------------------------------------------------------+
| For more information please visit https://lnmp.org |
+-----------------------------------------------------------------------+
include/main.sh:行681: /usr/local/php/bin/php-config: 没有那个文件或目录
include/main.sh:行682: /usr/local/php/bin/php-config: 没有那个文件或目录
Current PHP Version:
You can get version number from http://www.php.net/
Please enter a PHP Version you want:
输入要升级的PHP的版本即可,原以为会很顺利,结果发现报错了,大概的报错信息如下:
/bin/lnmp /etc/init.d/php-fpm no such file or directory
google搜了一圈,基本上都是让你重新创建/etc/init.d/php-fpm文件,但是创建依然不小,看了lnmp的错误日志,发现如下信息:
checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:
Requested 'libzip >= 0.11' but version of libzip is 0.10.1
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
原来是libzip的版本过低导致的问题
安装高版本libzip
- 先卸载旧版本
yum -y remove libzip-devel
- 下载最新的libzip版本,如果下载的是1.5.x版本的还需要安装cmake 相关命令如下:
yum -y install cmake
wget https://libzip.org/download/libzip-1.7.3.tar.gz
tar -zxvf libzip-1.7.3.tar.gz
cd libzip-1.7.3
mkdir build
cd build
cmake ..
make && make install
安装的过程又出错了,提示cmake的版本过低
安装cmake
如果安装的低版本,此步骤可以跳过
安装新版本的cmake
cd /opt
wget https://cmake.org/files/v3.18/cmake-3.18.2.tar.gz
tar zxvf cmake-3.18.2-Linux-x86_64.tar.gz
解压成功后,就可以在 /opt 目录下看到一个 cmake-3.10.2-Linux-x86_64 目录
然后添加cmake环境变量,编辑 /etc/profile.d/cmake.sh 文件,写入以下内容:
export CMAKE_HOME=/opt/cmake-3.18.2-Linux-x86_64
export PATH=$PATH:$CMAKE_HOME/bin
保存并退出,执行命令让cmake环境文件生效:
source /etc/profile
此时,你再次查看cmake版本,
cmake -version
显示为cmake version 3.18.2,说明更新成功了
配置PKG_CONFIG_PATH环境变量
上面的几步都完成后,再次安装PHP7.4.10版本,发现还是提示文章中开头的错误,也就是libzip版本依然过低,这时候查看一下libzip.so的路径,
比如我的在/usr/local/lib64下,因此在lnmp目录环境下配置如下命令:
export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/
让configure过程找到libzip,这样就可以完成php7.4的升级编译安装了
安装libzip.so.5依赖包
本以为上一步设置完成就可以了,再次安装的时候又报错了,到这个时候心态已有点爆炸了,再次查看升级的报错日志,如下:
Generating phar.phar
/lnmp1.7/src/php-7.4.10/sapi/cli/php: error while loading shared libraries: libzip.so.5: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.phar] 错误 127
一般是相应库的路径不对导致的,于是查找libzip.so.5,命令如下:
[root@instance-1-tw ~]# find / -name libzip.so.5 -print
/root/libzip-1.7.3/build/lib/libzip.so.5
/usr/local/lib64/libzip.so.5
然后将执行以下命令,将依赖包链接到lib目录
ln -s /usr/local/lib64/libzip.so.5 /usr/lib64
大功告成
最后再次安装,终于成功了,如下显示:
+--------------------------------------------------------------------+
| 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.
...
+-------------------------------------------+
| Manager for LNMP, Written by Licess |
+-------------------------------------------+
| https://lnmp.org |
+-------------------------------------------+
Starting LNMP...
Starting nginx... done
Starting MySQL.. SUCCESS!
Starting php-fpm done
======== upgrade php completed ======
再次查看php的版本,如下:
[root@instance-1-tw ~]# php -v
PHP 7.4.10 (cli) (built: Sep 14 2020 17:35:05) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
终于终于,升级成功了,不容易。。。
升级失败后的恢复方案
如果要恢复原PHP版本,,将 /usr/local/ 下 oldphp 日志的目录重命名为 php,如图:
并将 /usr/local/oldphp日期/init.d.php-fpm.bak.日期 的文件拷贝到 /etc/init.d/ 目录下重命名为 php-fpm
再重新启动php-fpm,如下:
service php-fpm start
再重新加载nginx后即可:
service nginx restart
以上,感谢阅读,End!!!