Ubuntu 16.04 PHP升级为PHP 7.4
环境:
- Ubuntu 16.04.6 LTS
- PHP 5.6.40
- Nginx
目标:
将PHP版本升级为7.4,以应对WordPress提示PHP版本过时问题。
升级步骤:
将repos.zend.com GPG密钥添加到您的apt密钥链中
curl -s https://repos.zend.com/zend.key | gpg --dearmor > /usr/share/keyrings/zend.gpg
1将repos.zend.com存储库添加到您的apt源列表中
sudo echo "deb [signed-by=/usr/share/keyrings/zend.gpg] https://repos.zend.com/zendphp/deb_ubuntu1604/ zendphp non-free" > /etc/apt/sources.list.d/zendphp.list
1更新您的程序包来源
sudo apt-get update
1如果有报错,则将第2步的命令改为
sudo echo "deb [arch=amd64 signed-by=/usr/share/keyrings/zend.gpg] https://repos.zend.com/zendphp/deb_ubuntu1604/ zendphp non-free" > /etc/apt/sources.list.d/zendphp.list
1然后再去执行
sudo apt-get update
1如果报了如下错:
E: Failed to fetch https://repos.zend.com/zendphp/deb_ubuntu1604/pool/libapache2-mod-php7.4-zend_7.4.33.2-1_amd64.deb 401 Unauthorized E: Failed to fetch https://repos.zend.com/zendphp/deb_ubuntu1604/pool/php7.4-zend_7.4.33.2-1_all.deb 401 Unauthorized
1
2
3则需要去https://www.zend.com/products/zendphp-enterprise/trial 注册一个账号,
然后执行如下命令:
sudo \ echo "machine repos.zend.com login {LOGIN_OR_ORDER_ID} password {PASSWORD}" \ > /etc/apt/auth.conf.d/zendphp.conf
1
2
3注:{LOGIN_OR_ORDER_ID}和{PASSWORD}换成实际的,最终的conf文件里没有{}
安装PHP程序包
sudo apt-get install php7.4-zend
sudo apt-get install php7.4-zend-fpm
sudo update-alternatives --set php /usr/bin/php7.4-zend
sudo apt-get install php7.4-zend-mysql
sudo apt-get install php7.4-zend-curl
sudo apt-get install php7.4-zend-dom
sudo apt-get install php7.4-zend-imagick
sudo apt-get install php7.4-zend-zip
sudo apt-get install php7.4-zend-gd
sudo apt-get install php7.4-zend-intl
sudo apt-get install php7.4-zend-xml
sudo apt-get install php7.4-zend-mbstring
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
启动fpm
sudo systemctl start php7.4-zend-fpm
1配置nginx
location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-zend-fpm.sock; }
1
2
3
4重启nginx
service nginx restart
1查看结果
最终,成功将我们WordPress的PHP版本升级到了7.4.33.2,完美解决问题
参考资料:
Installing ZendPHP on DEB (Debian and Ubuntu) (opens new window)
上次更新: 2023/11/11, 14:53:26