Install php7.2 instead of php5.4 on Amazon Linux 2

Problem: When you start a new Amazon Linux 2 AMI server, and try to install php via command:

yum install php

After install successfully and check the version, you would see php -v

PHP 5.4.16 (cli) (built: Oct 31 2019 18:34:05)

However, the latest php version is 7.2 and you want to have a new version.

Solution: You can enable it via amazon linux extras with this command:

sudo amazon-linux-extras enable php7.2

Once it is enabled, follow the instructions to install:

yum clean metadata
yum install php-cli php-pdo php-fpm php-json php-mysqlnd

That’s it. Check the php -v again and it shows:

PHP 7.2.28 (cli) (built: Mar 2 2020 19:38:11) ( NTS )

By Victor Leung

Experience in software development, consulting services and technical product management. Understanding of business and technology with an MBA in Finance and a Master degree in Computer Science. AWS Certified Solution Architect with experience in building products from scratch and serving as a charismatic leader.

Leave a comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: