To install PHP 7.2, 7.3, 7.4, or 8.0 on Amazon Linux 2, you can use the following steps:
sudo amazon-linux-extras install -y php7.2
Replace php7.2
with php7.3
, php7.4
, or php8.0
depending on the version you want to install.
sudo yum install -y php
This will install the latest version of PHP available in the repository.
sudo service httpd restart
This will apply the changes and make PHP available to your web server.
Create a PHP file in the document root of your web server with the following code:
<?php phpinfo(); ?>
Save the file and access it from a web browser. You should see a page with information about your PHP installation, indicating that PHP is working correctly.