AWS WordPress 3: Setup LAMP

Overview

This post is the third of a 6-post series with step-by-step procedures that I followed recently to setup WordPress on AWS for this version of the website. In this post, a LAMP stack is setup on the AWS instance. LAMP is an acronym for Linux, Apache, MySQL, and PHP.

Installing Apache Web Server Package:

To install the Apache web server package on the EC2 instance, enter the following command:

sudo apt install apache2

To verify if the installation was successful, enter the elastic IP address (http://xx.xx.xx.xx) into a web browser and see if this is the response:

Installing MySQL Server Package:

Prior to installing the MySQL server package, it is a good time to update:

sudo apt-get update

To install the MySQL server package on the EC2 instance, enter the following command. Note that a new password will need to be created. After entering the password, it is important to ‘tab’ to the ‘OK’ button so that it is highlighted first, then press enter.

sudo apt-get install mysql-server

To perform the MySQL security installation, enter the following command:

mysql_secure_installation

Enter the password from the previous step. Replies to a series of questions will be requested:

Installing PHP7:

To install the PHP7 and Apache PHP module, enter the following command:

sudo apt-get -y install php7.0 libapache2-mod-php7.0

Then, restart Apache:

sudo systemctl restart apache2

To test the PHP installation, a small PHP file ‘info.php’ will be created and placed in the default website directory ‘/var/www/html’:

sudo nano /var/www/html/info.php

Add the following line in the nano editor:

<?php phpinfo(); ?>

Enter ctrl-x, type y, and return to save.

Change the ownership of this file:

sudo chown www-data:www-data /var/www/html/info.php

Time to check PHP operation. In a browser window, enter the following address replacing the ‘xx’ with the Elastic IP address (http://xx.xx.xx.xx/info.php). The PHP file will display a ton of information about the current PHP installation.

Scrolling down through the PHP information reveals that MySQL is not listed meaning that MySQL support in PHP isn’t installed yet. The php7.0-mysql package needs to be installed. In addition, other useful PHP modules can be installed at this point: