6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS EC2 AmazonLinux2 extrasを使ってPHP8をインストールする

Posted at

概要

  • EC2のAmazonLinux2インスタンスにamazon-linux-extrasを用いてPHP8.0を入れる方法をまとめる。

前提

  • 若干古いが下記の方法を応用してAmazon Linux2インスタンスを立てた
  • コマンドは特筆しない限り前のコマンドと同じディレクトリで実行しているものとする

方法

  1. インスタンス起動後ssh接続し、そのままのディレクトリで下記コマンドを実行してyumを最新状態にする。

    $ sudo yum update
    
  2. 下記コマンドを実行してAmazon Linux Extrasが入っているか確認する。(エラーがでなければ入っている)

    $ which amazon-linux-extras
    
  3. 入っていなかった場合、下記を実行して導入する。

    $ sudo yum install amazon-linux-extras
    
  4. 下記を実行してPHP8.0のパッケージが含まれている事を確認する。下記の様にヒットしたらPHP8.0のパッケージは含まれている。

    $ amazon-linux-extras | grep "php"
    > 42  php7.4                   available    [ =stable ]
    > 51  php8.0                   available    [ =stable ]
    
  5. 下記コマンドを実行してnginxを導入するのに必要なコマンドを出力する。

    $ sudo amazon-linux-extras enable "php8.0"
    
  6. 下記の様に出力される。

    $ sudo amazon-linux-extras enable php
    Topic php is not found.
    [ec2-user@ip-10-0-10-20 ~]$ amazon-linux-extras | grep "php"
     42  php7.4                   available    [ =stable ]
     51  php8.0                   available    [ =stable ]
    [ec2-user@ip-10-0-10-20 ~]$ amazon-linux-extras | grep "php"
     42  php7.4                   available    [ =stable ]
     51  php8.0                   available    [ =stable ]
    [ec2-user@ip-10-0-10-20 ~]$ sudo amazon-linux-extras enable "php8.0"
      0  ansible2                 available    \
            [ =2.4.2  =2.4.6  =2.8  =stable ]
      2  httpd_modules            available    [ =1.0  =stable ]
      3  memcached1.5             available    \
            [ =1.5.1  =1.5.16  =1.5.17 ]
      5  postgresql9.6            available    \
            [ =9.6.6  =9.6.8  =stable ]
      6  postgresql10             available    [ =10  =stable ]
      9  R3.4                     available    [ =3.4.3  =stable ]
     10  rust1                    available    \
            [ =1.22.1  =1.26.0  =1.26.1  =1.27.2  =1.31.0  =1.38.0
              =stable ]
     11  vim                      available    [ =8.0  =stable ]
     18  libreoffice              available    \
            [ =5.0.6.2_15  =5.3.6.1  =stable ]
     19  gimp                     available    [ =2.8.22 ]
     20  docker=latest            enabled      \
            [ =17.12.1  =18.03.1  =18.06.1  =18.09.9  =stable ]
     21  mate-desktop1.x          available    \
            [ =1.19.0  =1.20.0  =stable ]
     22  GraphicsMagick1.3        available    \
            [ =1.3.29  =1.3.32  =1.3.34  =stable ]
     23  tomcat8.5                available    \
            [ =8.5.31  =8.5.32  =8.5.38  =8.5.40  =8.5.42  =8.5.50
              =stable ]
     24  epel                     available    [ =7.11  =stable ]
     25  testing                  available    [ =1.0  =stable ]
     26  ecs                      available    [ =stable ]
     27  corretto8                available    \
            [ =1.8.0_192  =1.8.0_202  =1.8.0_212  =1.8.0_222  =1.8.0_232
              =1.8.0_242  =stable ]
     28  firecracker              available    [ =0.11  =stable ]
     29  golang1.11               available    \
            [ =1.11.3  =1.11.11  =1.11.13  =stable ]
     30  squid4                   available    [ =4  =stable ]
     32  lustre2.10               available    \
            [ =2.10.5  =2.10.8  =stable ]
     33  java-openjdk11           available    [ =11  =stable ]
     34  lynis                    available    [ =stable ]
     35  kernel-ng                available    [ =stable ]
     36  BCC                      available    [ =0.x  =stable ]
     37  mono                     available    [ =5.x  =stable ]
     38  nginx1=latest            enabled      [ =stable ]
     39  ruby2.6                  available    [ =2.6  =stable ]
     40  mock                     available    [ =stable ]
     41  postgresql11             available    [ =11  =stable ]
      _  php7.4                   available    [ =stable ]
     43  livepatch                available    [ =stable ]
     44  python3.8                available    [ =stable ]
     45  haproxy2                 available    [ =stable ]
     46  collectd                 available    [ =stable ]
     47  aws-nitro-enclaves-cli   available    [ =stable ]
     48  R4                       available    [ =stable ]
      _  kernel-5.4               available    [ =stable ]
     50  selinux-ng               available    [ =stable ]
     51  php8.0=latest            enabled      [ =stable ]
     52  tomcat9                  available    [ =stable ]
     53  unbound1.13              available    [ =stable ]
     54  mariadb10.5              available    [ =stable ]
     55  kernel-5.10=latest       enabled      [ =stable ]
     56  redis6                   available    [ =stable ]
     57  ruby3.0                  available    [ =stable ]
     58  postgresql12             available    [ =stable ]
     59  postgresql13             available    [ =stable ]
     60  mock2                    available    [ =stable ]
     61  dnsmasq2.85              available    [ =stable ]
    
    Now you can install:
     # yum clean metadata
     # yum install php-cli php-pdo php-fpm php-mysqlnd
    
  7. 下記の部分がインストールに必要なコマンドなので実行する。(必要に応じて頭にsudoをつけたりする必要がある。)

    Now you can install:
     # yum clean metadata
     # yum install php-cli php-pdo php-fpm php-mysqlnd
    
  8. 筆者は下記コマンドを実行する。

    $ sudo yum clean metadata
    $ sudo yum install php-cli php-pdo php-fpm php-mysqlnd
    
  9. 下記のようにインストール可否を問われたのでyを入力してEnterを押下する。

    =========================================================================================================================================================================================================================================
     Package                                               アーキテクチャー                                 バージョン                                                     リポジトリー                                                 容量
    =========================================================================================================================================================================================================================================
    インストール中:
     php-cli                                               x86_64                                           8.0.13-1.amzn2                                                 amzn2extra-php8.0                                           5.0 M
     php-fpm                                               x86_64                                           8.0.13-1.amzn2                                                 amzn2extra-php8.0                                           1.7 M
     php-mysqlnd                                           x86_64                                           8.0.13-1.amzn2                                                 amzn2extra-php8.0                                           189 k
     php-pdo                                               x86_64                                           8.0.13-1.amzn2                                                 amzn2extra-php8.0                                           122 k
    依存性関連でのインストールをします:
     libzip                                                x86_64                                           1.3.2-1.amzn2.0.1                                              amzn2-core                                                   62 k
     php-common                                            x86_64                                           8.0.13-1.amzn2                                                 amzn2extra-php8.0                                           1.2 M
    
    トランザクションの要約
    =========================================================================================================================================================================================================================================
    インストール  4 パッケージ (+2 個の依存関係のパッケージ)
    
    総ダウンロード容量: 8.3 M
    インストール容量: 41 M
    Is this ok [y/d/N]: y
    
  10. インストール後、下記コマンドを実行してインストールされたものを確認する。

    $ yum list installed | grep nginx
    php-cli.x86_64                        8.0.13-1.amzn2                 @amzn2extra-php8.0
    php-common.x86_64                     8.0.13-1.amzn2                 @amzn2extra-php8.0
    php-fpm.x86_64                        8.0.13-1.amzn2                 @amzn2extra-php8.0
    php-mysqlnd.x86_64                    8.0.13-1.amzn2                 @amzn2extra-php8.0
    php-pdo.x86_64                        8.0.13-1.amzn2                 @amzn2extra-php8.0
    
  11. 下記コマンドを実行してPHPのバージョンを確認する。このコマンドが実行できれば問題なくPHP8.0のインストールが完了している。

    $ php -v
    PHP 8.0.13 (cli) (built: Dec 17 2021 17:28:11) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v4.0.13, Copyright (c) Zend Technologies
    
6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?