How to install PHP 7.2/7.3/7.4 or 8.0 on Amazon Linux 2

Amazon Linux 2 comes with PHP pre-installed, but it might not be the version you need. If you want to install a different version of PHP, you can use the package manager yum to do so.

Here’s an example of how to install PHP 7.4 on Amazon Linux 2:

  1. Install the PHP 7.4 package:
sudo amazon-linux-extras install php7.4
  1. Start the PHP-FPM service:
sudo systemctl start php-fpm
  1. Enable the PHP-FPM service to start automatically on system boot:
sudo systemctl enable php-fpm

You can also install other version of PHP (7.2, 7.3, 8.0) by replacing the package name, instead of php7.4 in the command above, use php7.2, php7.3 or php8.0 respectively.

Once the installation is complete, you can verify the version of PHP by running the command php -v.

Please note that these commands are for a basic setup and they will install the latest version available of PHP, also before installing any package it’s recommended to have a backup plan in case something goes wrong, and also to test the installation before applying it to your production environment.

Also, it’s worth noting that Amazon Linux 2 comes with a specific version of the system libraries, so you might need to configure your PHP installation accordingly. Additionally, the process of installing PHP may differ depending on the specific version of Amazon Linux 2 that you are running.

Leave a Comment