php - Amazon Linux2:为 WordPress 应用程序将 PHP 版本从 7.4 升级到 8.0

我在 Amazon Linux 2 EC2 实例上安装了一个 WordPress 应用程序。当前安装的 PHP 版本是 7.4。我想将此版本更新到 8.0

我在 EC2 终端中执行了以下命令来升级 PHP :

$ amazon-linux-extras | grep php

42  php7.4=latest            enabled      [ =stable ]
_  php8.0                   available    [ =stable ]

$ amazon-linux-extras disable php7.4

....
....
42 php7.4 available [ =stable ]
.....
50 selinux-ng available [ =stable ]
51 php8.0 available [ =stable ]
.....
61 dnsmasq2.85 available [ =stable ]
* Extra topic has reached end of support.

$ amazon-linux-extras | grep php

42 php7.4 available [ =stable ]
51 php8.0 available [ =stable ]

$ amazon-linux-extras enable php8.0

....
42 _ php7.4 available [ =stable ]
....
51 php8.0=latest enabled [ =stable ]
.....
Now you can install:
# yum clean metadata
# yum install php-cli php-pdo php-fpm php-mysqlnd

$ yum clean metadata

Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Cleaning repos: amzn2-core amzn2extra-docker amzn2extra-nginx1.12 amzn2extra-php8.0 mysql-connectors-community mysql-tools-community
: mysql80-community
21 metadata files removed
12 sqlite files removed
0 metadata files removed

$ yum info php

51 packages excluded due to repository priority protections
Available Packages
Name : php
Arch : x86_64
Version : 8.0.16
Release : 1.amzn2
Size : 3.3 M
Repo : amzn2extra-php8.0/2/x86_64

$ php -v

**PHP 7.4.28** (cli) (built: Feb 28 2022 23:38:08) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

$ yum install php-cli php-pdo php-fpm php-mysqlnd

--> Finished Dependency Resolution
Error: Package: php-json-7.4.28-1.amzn2.x86_64 (@amzn2extra-php7.4)
           Requires: php-common(x86-64) = 7.4.28-1.amzn2
           Removing: php-common-7.4.28-1.amzn2.x86_64 (@amzn2extra-php7.4)
               php-common(x86-64) = 7.4.28-1.amzn2
           Updated By: php-common-8.0.16-1.amzn2.x86_64 (amzn2extra-php8.0)
               php-common(x86-64) = 8.0.16-1.amzn2
           Available: php-common-5.4.16-43.amzn2.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-43.amzn2
           Available: php-common-5.4.16-43.amzn2.0.1.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-43.amzn2.0.1
           Available: php-common-5.4.16-43.amzn2.0.2.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-43.amzn2.0.2
           Available: php-common-5.4.16-43.amzn2.0.3.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-43.amzn2.0.3
           Available: php-common-5.4.16-43.amzn2.0.4.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-43.amzn2.0.4
           Available: php-common-5.4.16-45.amzn2.0.5.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-45.amzn2.0.5
           Available: php-common-5.4.16-45.amzn2.0.6.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-45.amzn2.0.6
           Available: php-common-5.4.16-46.amzn2.0.2.x86_64 (amzn2-core)
               php-common(x86-64) = 5.4.16-46.amzn2.0.2
           Available: php-common-8.0.0-2.amzn2.x86_64 (amzn2extra-php8.0)
               php-common(x86-64) = 8.0.0-2.amzn2
           Available: php-common-8.0.2-1.amzn2.x86_64 (amzn2extra-php8.0)
               php-common(x86-64) = 8.0.2-1.amzn2
           Available: php-common-8.0.6-1.amzn2.x86_64 (amzn2extra-php8.0)
               php-common(x86-64) = 8.0.6-1.amzn2
           Available: php-common-8.0.8-1.amzn2.x86_64 (amzn2extra-php8.0)
               php-common(x86-64) = 8.0.8-1.amzn2
           Available: php-common-8.0.13-1.amzn2.x86_64 (amzn2extra-php8.0)
               php-common(x86-64) = 8.0.13-1.amzn2
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

从输出可以看出上述安装失败。我也用 --skip-broken 尝试了上述命令。但是输出是一样的。

从输出中,我认为问题出在 php-json 包上。所以我试图删除 php-json 包:

$ yum -y remove php-json-7.4.28-1.amzn2.x86_64

Removed:
  php-json.x86_64 0:7.4.28-1.amzn2

Dependency Removed:
  php-cli.x86_64 0:7.4.28-1.amzn2             php-common.x86_64 0:7.4.28-1.amzn2           php-fpm.x86_64 0:7.4.28-1.amzn2
  php-gd.x86_64 0:7.4.28-1.amzn2              php-mbstring.x86_64 0:7.4.28-1.amzn2         php-mysqlnd.x86_64 0:7.4.28-1.amzn2
  php-opcache.x86_64 0:7.4.28-1.amzn2         php-pdo.x86_64 0:7.4.28-1.amzn2              php-xml.x86_64 0:7.4.28-1.amzn2

Complete!

我再次尝试安装相同的软件包,如下所示:

$ yum install php-cli php-pdo php-fpm php-mysqlnd

.....
Installed:
  php.x86_64 0:8.0.16-1.amzn2

Dependency Installed:
  apr.x86_64 0:1.7.0-9.amzn2   apr-util.x86_64 0:1.6.1-5.amzn2.0.2  ....
.... .... .....
$ systemctl restart nginx
$ systemctl restart php-fpm.service

现在我尝试访问该站点,浏览器显示 HTTP 502 错误。我在哪里犯了错误?

作为参考,我使用以下链接进行升级:

  1. https://computingforgeeks.com/how-to-install-php-8-on-amazon-linux/
  2. https://www.cyberciti.biz/faq/install-php-7-2-7-3-7-4-0r-8-0-on-amazon-linux-2/
  3. https://omkz.net/en-ec2-php8-laravel8/

回答1

我有同样的问题,我的实例只是一个 LAMP 登台服务器,并不那么重要。

所以,我删除了 php-json sudo yum remove php-json 然后运行了 php 的安装

sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}

这一切似乎都奏效了,我的应用程序仍然有效。

PHP 8.0.16 (cli) (built: Mar  1 2022 00:31:45) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.16, Copyright (c) Zend Technologies

只有一条评论:在流程结束时 AWS 告诉我

php-json is available in Amazon Linux Extra topic "php7.4"

To use, run
# sudo amazon-linux-extras install php7.4

希望能帮助到你。

相似文章