How to update php on Amazon linux 2

Symptoms

A "recommended improvement" has appeared in the site health of the WordPress administrator screen, asking you to raise the php version to 7.3 or higher.

environment

Thing you want to do

Upgrade php. I don't know what it is, so keep it up to date.

What i did

Check the current version

$ php -v
PHP 7.2.30 (cli) (built: May  5 2020 18:04:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

As angry with WordPress. old.

Connect to an AWS EC2 Linux instance using SSH

In the usual way. I used a mac terminal. Reference: Connecting to your Linux instance using SSH

Install amazon-linux-extras (skip if you're done)

Use which command to verify that the amazon-linux-extras package is installed.

$ which amazon-linux-extras
/usr/bin/amazon-linux-extras

If the amazon-linux-extras package is not installed, use yum to install it.

$ sudo yum install -y amazon-linux-extras

View list of available topics

$ amazon-linux-extras
#abridgement
 13  ruby2.4                  available    \
        [ =2.4.2  =2.4.4  =2.4.7  =stable ]
  _  php7.2                   available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14
          =7.2.16  =7.2.17  =7.2.19  =7.2.21  =7.2.22  =7.2.23
          =7.2.24  =7.2.26  =stable ]
  _  lamp-mariadb10.2-php7.2  available    \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17
          =10.2.10_7.2.19  =10.2.10_7.2.22  =10.2.10_7.2.23
          =10.2.10_7.2.24  =stable ]
#abridgement
 30  squid4                   available    [ =4  =stable ]
  _  php7.3                   available    \
        [ =7.3.2  =7.3.3  =7.3.4  =7.3.6  =7.3.8  =7.3.9  =7.3.10
          =7.3.11  =7.3.13  =stable ]
#abridgement
 42  php7.4                   available    [ =stable ]
#abridgement

Since it is displayed in a row, I omitted a part. At this point php7.4 seems to be the latest php available for amazon-linux-extras.

Apply php7.4

First, stop the old php7.2.

$ sudo amazon-linux-extras disable php7.2

Enable php7.4.

$ sudo amazon-linux-extras enable php7.4
#abridgement
 13  ruby2.4                  available    \
        [ =2.4.2  =2.4.4  =2.4.7  =stable ]
  _  php7.2                   available    \
        [ =7.2.0  =7.2.4  =7.2.5  =7.2.8  =7.2.11  =7.2.13  =7.2.14
          =7.2.16  =7.2.17  =7.2.19  =7.2.21  =7.2.22  =7.2.23
          =7.2.24  =7.2.26  =stable ]
  _  lamp-mariadb10.2-php7.2  available    \
        [ =10.2.10_7.2.0  =10.2.10_7.2.4  =10.2.10_7.2.5
          =10.2.10_7.2.8  =10.2.10_7.2.11  =10.2.10_7.2.13
          =10.2.10_7.2.14  =10.2.10_7.2.16  =10.2.10_7.2.17
          =10.2.10_7.2.19  =10.2.10_7.2.22  =10.2.10_7.2.23
          =10.2.10_7.2.24  =stable ]
#abridgement
 30  squid4                   available    [ =4  =stable ]
  _  php7.3                   available    \
        [ =7.3.2  =7.3.3  =7.3.4  =7.3.6  =7.3.8  =7.3.9  =7.3.10
          =7.3.11  =7.3.13  =stable ]
#abridgement
 42  php7.4=latest            enabled      [ =stable ]
#abridgement
Now you can install:
 # yum clean metadata
 # yum install php-cli php-pdo php-fpm php-json php-mysqlnd

Install topic

Sudo the bottom two lines of "Now you can install:" above. You can do it line by line, but connect it with && and execute it.

$ sudo yum clean metadata && yum install php-cli php-pdo php-fpm php-json php-mysqlnd

Installation verification and version confirmation

$ yum list installed php-cli php-pdo php-fpm php-json php-mysqlnd
Loaded plugin:extras_suggestions, langpacks, priorities, update-motd
Installed packages
php-cli.x86_64                                                                                7.4.5-1.amzn2                                                                             @amzn2extra-php7.4
php-fpm.x86_64                                                                                7.4.5-1.amzn2                                                                             @amzn2extra-php7.4
php-json.x86_64                                                                               7.4.5-1.amzn2                                                                             @amzn2extra-php7.4
php-mysqlnd.x86_64                                                                            7.4.5-1.amzn2                                                                             @amzn2extra-php7.4
php-pdo.x86_64                                                                                7.4.5-1.amzn2                                                                             @amzn2extra-php7.4

$ php -v
PHP 7.4.5 (cli) (built: Apr 23 2020 00:10:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

You did it! Finally restart httpd.service.

$ sudo systemctl restart httpd.service

If you check the site health of the WordPress administration screen,

The site is running the current version of PHP (7.4.5)

Now it's done!

reference

--Official AWS Q & A: https://aws.amazon.com/jp/premiumsupport/knowledge-center/ec2-install-extras-library-software/

Recommended Posts

How to update php on Amazon linux 2
How to install Anisble on Amazon Linux 2
How to update security on CentOS Linux 8
How to install php7.4 on Linux (Ubuntu)
[AWS EC2] How to install Maven on Amazon Linux 2
How to build a Python environment on amazon linux 2
[AWS] How to expand disk space on Amazon linux
How to install wkhtmltopdf (Amazon Linux2)
How to install VMware-Tools on Linux
How to install aws-session-manager-plugin on Manajro Linux
How to display emoji on Manjaro Linux
Upgraded mysql on Cloud9 (Amazon Linux) (5.5 to 5,7)
How to install packages on Alpine Linux
How to find large files on Linux
How to update easy_install
How to update Spyder
Update vscode on linux
How to update security on Ubuntu 19.10 Eoan Ermine
How to install Camunda Modeler on Manjaro Linux
How to build Java environment on Ubuntu (Linux)
Install PHP 7 series on Amazon Linux 2 with Amazon Linux Extras
How to use C216 Audio Controller on Arch Linux
How to update Python Tkinter to 8.6
How to install Linux on a 32bit UEFI PC
How to register on pypi
How to update with SQLAlchemy?
How to allow nologin users to log in on Linux
Put jenv on Amazon Linux
Update python on Mac to 3.7-> 3.8
Install tomcat 5.5 on Amazon Linux.
Use sshpass on Amazon linux2
Install Homebrew on Amazon Linux 2
How to install git on Linux such as EC2
Install strongSwan 5.9.1 on Amazon Linux 2
[Tips] How to use iPhone as webcam on Linux
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
[AWS EC2] How to install only MySQL client on Amazon Linux 2 and connect to RDS
A memo on how to easily prepare a Linux exercise environment
[For beginners] How to use for statements on Linux (variables, etc.)
[AWS EC2] Settings you want to do on Amazon Linux 2
How to create an ISO file (CD image) on Linux
[Linux] How to disable automatic update of /etc/resolv.conf file (Redhat)
Install Python Pillow on Amazon Linux
Easy copy to clipboard on Linux
Install oracle java8 on amazon linux2
How to install mysql-connector-python on mac
How to update Spyder in Anaconda
Notes on how to use pywinauto
How to install graph-tool on macOS
How to install pycrypto on Windows
How to deploy django-compressor on Windows
Install pyenv on EC2 (Amazon Linux)
Notes on how to use featuretools
How to install OpenCV on Mac
How to run matplotlib on heroku
How to install MBDyn (Linux Ubuntu)
How to install PyPy on CentOS
How to use homebrew on Debian
Misunderstanding on how to connect cnn
How to install TensorFlow on CentOS 7
Introducing Amplify to Amazon Linux 2 AMI