Amazon Linux 2, Apache 2.4, PHP 7.3

In this guide, I will explain the steps necessary to create an Amazon Linux 2 server with:

  • Apache 2.4
  • PHP 7.3
  • Common PHP modules.
  • No RDBMS (MySQL / MariaDB) – We won’t need that as you’re using RDS 🙂

Revision History

  • 2019-11-25: mcrypt Installation Instructions
  • 2019-11-24: Initial creation.

Step 1: Follow AWS Guide on LAMP

AWS created an awesome documentation on spinning up Amazon Linux 2 with LAMP. Follow steps 1 & 2 and forget about the other steps if you’re using RDS as your database provider (or another DB server).

Step 2: Disable PHP 7.2 amazon-linux-extras

If you went through Step 1, you now have LAMP 7.2 installed. You’re probably thinking, “wait a minute, I want PHP 7.3!”

This is where it is tricky, but I’m here to make it easy for you 😉 First, you need to disable the amazon-linux-extras PHP7.2 you just installed:

sudo amazon-linux-extras disable php7.2
sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2

Next, you will need to enable the PHP 7.3 packages:

sudo amazon-linux-extras enable php7.3

# Additional PHP addons you'll most likely need.
sudo yum install php-cli php-pdo php-fpm php-json php-mysqlnd

# Disable php7.3
# See "Updating Your Server"
sudo amazon-linux-extras disable php7.3

That’s it! Whenever you need to do an update on your server (using yum update), see the next section about that.

Updating Your Server

For server maintenance, run the following:

# Update LAMP
sudo amazon-linux-extras enable lamp-mariadb10.2-php7.2
sudo yum update -y
sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2

# Update php7.3
sudo amazon-linux-extras enable php7.3
sudo yum update -y
sudo amazon-linux-extras disable php7.3

Optional PHP Modules


Some of your legacy applications may rely on mcrypt. I’ve detailed the following on installing mcrypt and updating it to mcrypt 1.0.2.

This module is also deprecated per official PHP documentation. While this may work for the time being, your ultimate goal is to develop using something else.

To bake mcrypt into your server:

sudo yum install libmcrypt-dev

Future Updates: What if PHP 7.4 comes out and I need to update to that?

While PHP 7.4 isn’t out yet, I do get your concern. It’ll be the same process as we upgraded from PHP 7.2 to PHP 7.3.

First, we need to disable PHP 7.3:

sudo amazon-linux-extras disable php7.3

Next, we need to enable the future PHP 7.4:

sudo amazon-linux-extras enable lamp-mariadb10.2-php7.2
sudo yum update -y
sudo amazon-linux-extras disable lamp-mariadb10.2-php7.2
sudo amazon-linux-extras enable php7.4
sudo yum update -y
udo amazon-linux-extras disable php7.4


The following resources has helped me with this setup. I am grateful for their shared knowledge.

3 thoughts on “Amazon Linux 2, Apache 2.4, PHP 7.3

  1. Rtrauer says:

    Nice post. But if one need Mariadb or Mysql with php7.3 or php7.4 this is not available for AWS Linux 2.
    AWS should make this easier since php7.2 has entered its “Security maintenance” phase since Saturday, 30 November 2019 and has stopped receiving bug fixes. It will stop receiving security updates on Monday, 30 November 2020 at which point it will be unsuitable for use on a live site.

    • Duane Leem says:

      Hi Rtrauer,

      I had hope by now they should make this easier for sysadmins by now. PHP 7.4 will be mandatory in the near future and am hoping they include that in yum without having to the steps in this post.

      I have moved most of my applications to Kubernetes using official images so I didn’t have to continue to do the above. In the future, if AWS doesn’t make it easier and I need a full cloud virtual machine, I may have to visit other distros such as Ubuntu.

      Thanks so much,


      • Philla says:

        Is it really that difficult for the powers that be at Amazon to make this priority? It’s extremely risky holding this out till the 11th hour.

        I agree, if Amazon is not going to provide much-needed support to their OWN distro, I’ll probably start looking elsewhere.


Leave a Reply

Your email address will not be published.

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

%d bloggers like this: