Uninstall PHP 7.4 in CentOS 7.7 in Alibaba Cloud and install PHP 8
1. Reference:Based on Alibaba Cloud’s ECS and RDS, the personal blog migration has been upgraded to: Docker (based on budget considerations, ultimately not realized), LNMP (CentOS 7.7, Nginx 1.16, MySQL 5.7, PHP 7.4), the process of HTTPS , the previous environment was based on the automatic installation of OneInstack. PHP version 7.4 is no longer eligible for Shopify applications. It needs to be upgraded to version 8.1, trying to be consistent with the local environment. as shown in Figure 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. In Alibaba Cloud, create a snapshot of the disk to avoid data loss during the operation. as shown in Figure 2
3. Configure the CentOS 7 yum source, refer to:“CentOS, Ubuntu, Debian dependency source configuration” . Error when updating cache: 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
'\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. Check the content of the file /etc/yum.repos.d/centos-base.repo, it is no longer the correct format, and the download failed. The source of Alibaba Cloud no longer exists. as shown in Figure 3
5. Openhttps://mirrors.aliyun.com/repo/, confirm that the source centos-7.repo and epel-7.repo can be downloaded. Decided to manually edit the save content, and then update the cache. Error:[Errno 14]HTTP Error 502 – Bad Gateway. as shown in Figure 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. After stopping the instance, roll back the cloud disk. as shown in Figure 5
7, update the cache, still report an error.
[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. Reference:In Alibaba Cloud ECS, CentOS 7 migration (replace) to Alibaba Cloud Linux 3 . Open URL:https://oneinstack.com/auto/, based on the automatic installation of OneInStack, LNMP, PHP version 8.1, and copy the installation command are selected, as shown in Figure 6
9. After starting the ECS instance, enter the Alibaba Cloud Linux server based on Putty, paste the installation command, and then keep it stuck at –php_extensions fileinfo. Press Ctrl + C to stop the installation process. as shown in Figure 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. In the installation command, the PHP extension only keeps Imagick, Redis, and other extensions will be installed on demand. If the components are not installed before, the subsequent installation will be supplemented, and the unified entrance is ./install.sh . Still stuck at –php_extensions FileInfo, confirm that OneInStack does not support the installation of extended FileInfo under PHP 8.1. Next, try to install this extension yourself.
[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. Check the PHP version
[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. My ECS memory is 1 GB configuration. Compiling FileInfo takes up a lot of memory, which is the direct cause of incompilation. It was finally decided to improve the configuration of the ECS, and the memory was increased to 2 GB. Reference:When compiling and installing PHP extension FileInfo in Alibaba Cloud ECS, the solution is stuck (improve memory configuration)



![打开 https://mirrors.aliyun.com/repo/ ,确认源 Centos-7.repo 与 epel-7.repo 是可以下载的。决定手动编辑保存内容,然后更新缓存。报错:[Errno 14] HTTP Error 502 - Bad Gateway](https://www.shuijingwanwq.com/wp-content/uploads/2023/07/4-3.png)


