Installing PHP 7.2 Instead of PHP 5.4 on Amazon Linux 2
Problem
When you launch a new Amazon Linux 2 AMI server and try to install PHP using the following command:
yum install php
After a successful installation, if you check the version using php -v
, you’ll see:
PHP 5.4.16 (cli) (built: Oct 31 2019 18:34:05)
However, the latest PHP version is 7.2, and you may want to use this newer version instead.
Solution
You can enable PHP 7.2 via Amazon Linux Extras with the following command:
sudo amazon-linux-extras enable php7.2
Once it is enabled, follow the subsequent instructions to complete the installation:
yum clean metadata
yum install php-cli php-pdo php-fpm php-json php-mysqlnd
That’s it. Check the PHP version again using php -v
, and it should now display:
PHP 7.2.28 (cli) (built: Mar 2 2020 19:38:11) ( NTS )