Install PHP 8 on Amazon Linux 2

George Tseng
2 min readSep 1, 2022

Update the system.

$ sudo yum -y update

Linux updates often comes with newer kernel patches and reboot is required for the system to run in this new release.

$ sudo systemctl reboot

The packages and dependencies that will be required in the installation of PHP 8 on Amazon Linux 2 server are available in the EPEL and Remi repositories. The two RPM repositories need to be added manually by running the commands below in the terminal.

$ sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 
$ sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Update Yum index to confirm the two repositories are working.

$ sudo yum makecache 
Loaded plugins: langpacks, priorities, update-motd amzn2-core amzn2extra-docker epel/x86_64/metalink remi-safe (1/5): epel/x86_64/filelists_db (2/5): epel/x86_64/prestodelta (3/5): epel/x86_64/other_db (4/5): remi-safe/other_db (5/5): remi-safe/filelists_db Metadata Cache Created

Install the yum-utils package which provides yum-config-manager command line tool.

$ sudo yum -y install yum-utils

Confirm that PHP 8.0 topic is available in our Amazon Linux 2 machine.

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

Confirm php8.0 topic is available. Let’s enable it.

$ sudo yum-config-manager --disable 'remi-php*' 
$ sudo amazon-linux-extras enable php8.0

After repo is enabled, install PHP 8.0 on Amazon Linux 2 with standard PHP extensions.

$ sudo yum clean metadata 
$ sudo yum install php-{pear,cgi,pdo,common,curl,mbstring,gd,mysqlnd,gettext,bcmath,json,xml,fpm,intl,zip}

Confirm if dependency resolution is successful.

Transaction Summary ==================================================================== Install  11 Packages (+4 Dependent packages)  
Total download size: 10 M
Installed size: 48 M
Is this ok [y/d/N]: y

Check PHP version

$ php --version PHP 
8.0.16 (cli) (built: Mar 1 2022 00:31:45) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.16, Copyright (c) Zend Technologies

Install Apache httpd web server to test PHP scripts execution.

$ sudo yum -y install httpd 
$ sudo systemctl enable --now 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.