[SOLVED] Install PHP 7/8 On Amazon Linux 2

By default AWS Amazon Linux 2 will install PHP 5.4 if you run: yum install php. In this article you will learn how to Install PHP 7.4 On Amazon Linux 2 step by step. Also how to install PHP 8.0

Step1: Install Amazon Linux Extras

Make sure you already have installed Amazon Linux Extras in your system. Run command:

$ sudo yum install -y amazon-linux-extras

Step2: Select PHP Version

Command amazon-linux-extras will show all available PHP versions (and other packages) that can be installed from repository. Run:

$ sudo yum update
$ sudo amazon-linux-extras | grep php

As result you will see something like:

15  php7.2                   available    \
17  lamp-mariadb10.2-php7.2  available    \
31  php7.3                   available    \
42  php7.4                   available    [ =stable ]
51  php8.0                   available    [ =stable ]

Now enable PHP7.4:

$ sudo amazon-linux-extras enable php7.4

Step 3: Install PHP 7.4

Now you can install selected PHP 7.4

$ sudo yum clean metadata
$ sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd php-gd
Install PHP 7 On Amazon Linux 2

Step 4: Check Installed PHP Version

To confirm version of installed PHP run:

$ php -v

example output:

PHP 7.4.26 (cli) (built: Dec 17 2021 16:07:39) ( NTS )
Copyright (c) The PHP Group

PHP 7.4 successfully installed!

Conclusion

You just learn how to install PHP 7.x on AWS Linux 2. PHP 8 can be installed in the same way as PHP7.

How to Install PHP 8.0 on AWS Amazon Linux 2

  1. Enable PHP8.0 from extras

    $ sudo yum update
    $ sudo amazon-linux-extras enable php8.0

  2. Install clean metadata and install PHP

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

  3. Check version of installed PHP 8.0

    $ php -v

Discuss article in ArsTech Forum

   

If you like what you are reading, please:

Buy me a coffeeBuy me a coffee

arstech

Leave a Reply