AWS Cloud9 PHP7.2から8.0へUpdate

Cloud9 PHP8

まず、Amazon Linux Extras リポジトリからインストール可能なPHPパッケージを調査。
利用可能パッケージの一覧を、Amazon Linux 2 のシェルで amazon-linux-extras コマンドを使い、phpだけ抽出したのが以下。PHP8.0はインストール可能なようです。

$ amazon-linux-extras | grep php
 15  php7.2                          available    \
 17  lamp-mariadb10.2-php7.2=latest  enabled      \
  _  php7.3                          available    \
  _  php7.4                          available    [ =stable ]
  _  php8.0                          available    [ =stable ]

但しこの状態で、yum install を行うと、JSONのパッケージでエラーがでました。
調べたところPHP8では不要らしいので、php-jsonをyum eraseで削除してからinstallしました。

sudo yum -y update
sudo amazon-linux-extras disable php7.2 lamp-mariadb10.2-php7.2
sudo amazon-linux-extras enable php8.0
sudo yum clean metadata
sudo yum erase -y php-json
sudo yum install -y php php-cli php-mbstring php-pdo php-fpm php-mysqlnd php-devel php-pear
sudo pecl uninstall xdebug && sudo pecl install xdebug

【追記】2022/05/01 時点
sudo yum install が、エラーになりました。

hashicorp/2/x86_64/primary     FAILED [Errno 14] HTTPS Error 404 - Not Found
Trying other mirror.

 One of the configured repositories failed (Hashicorp Stable - x86_64),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=hashicorp ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable hashicorp
            subscription-manager repos --disable=hashicorp

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice

            yum-config-manager --save --setopt=hashicorp.skip_if_unavailable=true

failure: repodata/c9a8aa18b37e7a72392290df43e33c79189f8d4c-primary.xml.gz from hashicorp: [Errno 256] No more mirrors to try. [Errno 14] HTTPS Error 404 - Not Found

対処方法としては、表示の指示(Run the command with the repository temporarily disabled)に従い、インストール時のリポジトリを無効にしたら問題なく成功しました。

sudo yum --disablerepo=hashicorp install -y php php-cli php-mbstring php-pdo php-fpm php-mysqlnd php-devel php-pear