Site icon The Perpetual Student

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:

Revision History

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

mcrypt

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

Resources

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

Exit mobile version