How can one install PHP 7.4,7.3 or 7.2 on an Amazon Linux 2 virtual machine. Amazon Linux is an operating system designed to provide a stable, secure, and high performance execution environment for applications running on Amazon EC2. This guide will show you how you can easily install PHP 7.x on Amazon Linux 2 instance running in AWS or your development environment.
Confirm that the amazon-linux-extras package is installed:
$ which amazon-linux-extras
/usr/bin/amazon-linux-extras
If the command doesn’t return any output, then install the package that will configure the repository:
sudo yum install -y amazon-linux-extras
Install PHP 7.4, 7.3, 7.2 on Amazon Linux 2
Let’s confirm that PHP 7.x topic is available in our Amazon Linux 2 machine:
$ sudo amazon-linux-extras | grep php
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 ]
As we can see all PHP 7 topics, in this example we’ll enable php7.4 topic.
sudo amazon-linux-extras enable php7.4
sudo amazon-linux-extras disable php5.4
Now install PHP packages from the repository.
sudo yum clean metadata
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}
Accept installation of PHP 7 packages on Amazon Linux 2.
....
Transaction Summary
========================================================================================================================================================
Install 12 Packages (+14 Dependent packages)
Total download size: 15 M
Installed size: 61 M
Is this ok [y/d/N]: y
Check default PHP version:
$ php --version
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
To install PHP 7.2, make sure you disable 7.4 and 7.3 then enable 7.2.
sudo amazon-linux-extras disable php7.4
sudo amazon-linux-extras disable php7.3
sudo amazon-linux-extras enable php7.2
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}
Confirm version of PHP.
$ php -v
PHP 7.2.31 (cli) (built: Jul 2 2020 23:17:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Similar commands should be used when installing PHP 7.3 on Amazon Linux 2.
sudo amazon-linux-extras disable php7.4
sudo amazon-linux-extras disable php7.2
sudo amazon-linux-extras enable php7.3
sudo yum install php php-{pear,cgi,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip,imap}
CloudSpinx Engineers are available 24/7 to support you throughout your entire tech journey.