在 阿里云中的 CentOS 7.7 中卸载 PHP 7.4,然后安装 PHP 8
1、参考:基于阿里云的 ECS、RDS,将个人博客迁移升级至:Docker(基于预算考虑,最终未实现)、LNMP(CentOS 7.7、Nginx 1.16、MySQL 5.7、PHP 7.4)、HTTPS 的过程 ,之前的环境是基于 OneinStack 的自动安装。PHP 版本 7.4 已经不再符合 Shopify 应用的运行条件。需要升级至 8.1 版本,尽量与本地环境保持一致。如图1
[root@iZ23wv7v5ggZ ~]# php -v PHP 7.4.0 (cli) (built: Dec 5 2019 11:56:30) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.0, Copyright (c), by Zend Technologies
wangqiang@DESKTOP-QLPK8QM:/mnt/e/wwwroot/shopify-app/learn-php-app-ubuntu-2004-0605$ php -v PHP 8.1.18 (cli) (built: Apr 14 2023 04:39:24) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.18, Copyright (c) Zend Technologies with Zend OPcache v8.1.18, Copyright (c), by Zend Technologies
2、在阿里云中,将磁盘创建快照,避免操作过程中导致数据丢失。如图2
3、配置 CentOS 7 yum 源,参考:《CentOS、Ubuntu、Debian依赖源配置》 。更新缓存时报错:File contains no section headers. Loaded plugins: fastestmirror
[root@iZ23wv7v5ggZ ~]# cd /etc/yum.repos.d/ [root@iZ23wv7v5ggZ yum.repos.d]# ls -l total 8 -rw-r--r-- 1 root root 2523 Jan 28 2022 CentOS-Base.repo -rw-r--r-- 1 root root 664 Jan 28 2022 epel.repo [root@iZ23wv7v5ggZ yum.repos.d]# rm -rf /etc/yum.repos.d/*.repo [root@iZ23wv7v5ggZ yum.repos.d]# ls -l total 0 [root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7221 100 7221 0 0 3763 0 0:00:01 0:00:01 --:--:-- 3762 [root@iZ23wv7v5ggZ yum.repos.d]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7215 100 7215 0 0 11531 0 --:--:-- --:--:-- --:--:-- 11525 [root@iZ23wv7v5ggZ yum.repos.d]# yum makecache Loaded plugins: fastestmirror File contains no section headers. file: file:///etc/yum.repos.d/CentOS-Base.repo, line: 1 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n' [root@iZ23wv7v5ggZ yum.repos.d]# ls -l total 16 -rw-r--r-- 1 root root 7221 Jun 6 14:32 CentOS-Base.repo -rw-r--r-- 1 root root 7215 Jun 6 14:32 epel.repo [root@iZ23wv7v5ggZ yum.repos.d]#
4、查看文件 /etc/yum.repos.d/CentOS-Base.repo 的内容,其已经不再是正确的格式,下载失败了。阿里云的源已经不存在。如图3
5、打开 https://mirrors.aliyun.com/repo/ ,确认源 Centos-7.repo 与 epel-7.repo 是可以下载的。决定手动编辑保存内容,然后更新缓存。报错:[Errno 14] HTTP Error 502 – Bad Gateway。如图4
[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.cloud.aliyuncs.com * extras: mirrors.cloud.aliyuncs.com * updates: mirrors.cloud.aliyuncs.com http://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyun.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyun.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyun.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. Metadata Cache Created
6、停止实例后,回滚云盘。如图5
7、更新缓存,仍然报错。
[root@iZ23wv7v5ggZ yum.repos.d]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com http://mirrors.aliyun.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyun.com/epel/7/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyun.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyun.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 502 - Bad Gateway Trying other mirror. Metadata Cache Created
8、参考:在阿里云的 ECS 中,CentOS 7 迁移(更换)至 Alibaba Cloud Linux 3 。打开网址:https://oneinstack.com/auto/ ,基于 OneinStack 的自动安装,选择了 LNMP,PHP 版本 8.1,复制安装命令,如图6
9、启动 ECS 实例后,基于 PuTTY 进入 Alibaba Cloud Linux 服务器中,粘贴执行安装命令,然后一直卡在 –php_extensions fileinfo 处。按 Ctrl + C 中止掉安装过程。如图7
[root@iZ23wv7v5ggZ ~]# wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1 --php_option 11 --phpcache_option 1 --php_extensions imagick,fileinfo,imap,ldap,redis,mongodb --pureftpd --redis
10、在安装命令中 PHP 扩展仅保留 imagick,redis,其他扩展后续按需安装。如果之前没有安装组件,后续补充安装,统一入口为 ./install.sh 。仍然一直卡在 –php_extensions fileinfo 处,确认 OneinStack 不支持 PHP 8.1 下的扩展 fileinfo 的安装。后续自行想办法安装此扩展。
[root@iZ23wv7v5ggZ ~]# wget -c http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1 --php_option 11 --phpcache_option 1 --php_extensions imagick,redis --pureftpd --redis [root@iZ23wv7v5ggZ oneinstack]# ./install.sh ####################################################################### # OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+ # # For more information please visit https://oneinstack.com # ####################################################################### Please input SSH port(Default: 22): Do you want to install Web server? [y/n]: n Do you want to install Database? [y/n]: n Do you want to install PHP? [y/n]: n Do you want to install opcode cache of the PHP? [y/n]: n Please select PHP extensions: 0. Do not install 1. Install zendguardloader(PHP<=5.6) 2. Install ioncube 3. Install sourceguardian(PHP<=7.2) 4. Install imagick 5. Install gmagick 6. Install fileinfo 7. Install imap 8. Install ldap 9. Install phalcon(PHP>=5.5) 10. Install yaf(PHP>=7.0) 11. Install redis 12. Install memcached 13. Install memcache 14. Install mongodb 15. Install swoole 16. Install xdebug(PHP>=5.5) Please input numbers:(Default '4 11 12' press Enter) 6
12、查看 PHP 版本
[root@iZ23wv7v5ggZ ~]# php -v PHP 8.1.19 (cli) (built: Jun 7 2023 11:34:24) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.19, Copyright (c) Zend Technologies with Zend OPcache v8.1.19, Copyright (c), by Zend Technologies [root@iZ23wv7v5ggZ ~]#
13、我的 ECS 内存为 1 GB 配置。编译 fileinfo 非常占用内存,这是导致无法编译的直接原因。最终决定提升 ECS 的配置,内存提升至 2 GB 。参考:在阿里云 ECS 中编译安装 PHP 扩展 fileinfo 时,一直卡住的解决(提升内存配置)
1 条回复
[…] 在 阿里云中的 CentOS 7.7 中卸载 PHP 7.4,然后安装 PHP 8 […]