Install PHP 7.4 on Amazon Linux 2

George Tseng
1 min readSep 1, 2022

First, confirm the amazon-linux-extras package is installed

$ which amazon-linux-extras

If it is not installed.

$ sudo yum install -y amazon-linux-extras

Confirm PHP topic available on the machine.

$ sudo  amazon-linux-extras | grep 
42 php7.4 available [ =stable ]
51 php8.0 available [ =stable ]

Enable PHP7.4 topic

$ sudo amazon-linux-extras enable php7.4

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

.....
php-pdo x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 133 k php-process x86_64 7.4.5-1.amzn2 amzn2extra-php7.4 88 k
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

Install Apache httpd web server to test PHP scripts execution.

$ sudo yum -y install httpd 
$ sudo systemctl enable httpd

Create PHP info script inside default apache web root.

$ sudo tee /var/www/html/phpinfo.php<<EOF <?php phpinfo(); ?> EOF

Open your web browser and input http://serverip_or_hostname/phpinfo.php

--

--

George Tseng

An application developer with extensive experience and enthusiastic about new tech currently working in IT Department of a manufacture company.