Install PHP 7.4|7.3|7.2 on Amazon Linux 2

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.

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

The web browser is the key arsenal that we use to browse the internet. If you want to access information […]

In this guide,we will look at how you can install Java 11 on Oracle Linux 8. Java is a widely […]

The adoption of Containers and microservice architectures has been amazing and speedy in the past few years. Docker is widely […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.