
Updated: June 2025
Overview
This post is the third part of a 6-post series with step-by-step procedures that I use to setup a simple WordPress website on AWS. In this post, a LAMP stack is setup on the AWS instance. LAMP is an acronym for Linux, Apache, MySQL, and PHP.
Note: The original version for this series was written in 2016 with EC2 servers running Ubuntu 16.04. This series has been completely updated in mid 2025. An example website, Seattle Hobbies, will be used throughout this series. The development of the Seattle Hobbies website assumes a simple low-maintenance website with low visitor count with no auto-scaling or redundancy. As such, implementation and configuration are easy. I will most likely seek the support of professional web-dev experts if I want to establish a sophisticated website that handles commerce or significant traffic with lots of site visitors.
Reference Material:
Much of the material in this post comes from the excellent Tutorial ‘How To Install LAMP Stack (Apache, MySQL, PHP) on Ubuntu’ by Kong Yang, Erika Heidi, Sasha Abid, and Vinayak Baronial.
Installing Apache Web Server Package:
If not logged in, then log into AWS SSH as user2 (e.g., alternate user from previous post) via a command line interface (e.g., terminal on the Mac or PuTTY on Windows) as described in AWS WordPress 2: Improve Security.
To install the Apache web server package on the EC2 instance, enter the following command:
sudo apt install apache2 -y
To allow connections on the HTTP port 80 as the initial default UFW firewall configuration, enter the following command:
sudo ufw allow in "Apache"
To verify installation, enter the following command:
apachectl -v
The response should be similar to:
Server version: Apache/2.4.58 (Ubuntu) Server built: 2025-04-03T14:36:49
To verify if the installation was successful, enter either the elastic IP address (e.g., http://44.247.136.248) or the website name (e.g., http://seattlehobbies.com) into a web browser and see if this is the response:

Installing MySQL Server Package:
To install the MySQL server package on the EC2 instance, enter the following command.
sudo apt-get install mysql-server -y
To avoid an installation error, a configuration step needs to be completed prior to performing the MySQL security installation. Open MySQL with the following command:
sudo mysql
At this point, the prompt has changed to the MySQL prompt indicating you are now in the MySQL database.
Enter the following MySQL command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
After making this change to the MySQL database which created a root user with a placeholder password, exit MySQL with this command:
exit
To perform the MySQL security installation, enter the following command:
sudo mysql_secure_installation
Note that the first prompt requests the password for the user root. Reply with ‘password’ which was the placeholder from the previous step. Here are the replies to the series of prompts requested during MySQL setup:
Enter password for user root: password Would you like to setup VALIDATE PASSWORD component? n Change password for root? n Remove anonymous users? y Disallow root login remotely? y Remove test database and access to it? y Reload privilege tables now? y
Installing PHP:
To install the PHP, Apache PHP, and the MySQL PHP packages enter the following command:
sudo apt-get -y install php libapache2-mod-php php-mysql
Confirm the version of PHP with the following command:
php -v
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 lines 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 either the elastic IP address (e.g., http://44.247.136.248/info.php) or the website name (e.g., http://seattlehobbies.com/info.php). The PHP file will display a ton of information about the current PHP installation.

Other useful PHP modules can be installed at this point:
sudo apt-get -y install php-cgi php-cli php-curl php-json sudo apt-get -y install php-gd php-imagick php-mbstring php-intl php-pspell sudo apt-get -y install php-imap php-tidy php-xml php-xsl php-opcache php-zip sudo apt-get -y install php-memcache php-sqlite3 php-common php-memcached
Then, restart Apache:
sudo systemctl restart apache2
Reloading the browser window with either the elastic IP address (e.g., http://44.247.136.248/info.php) or the website name (e.g., http://seattlehobbies.com/info.php) will now include PHP information about several other packages.
Installing APCu PHP cache to speed up PHP:
APCu speeds up PHP pages by caching and optimizing PHP intermediate code. To install APCu, enter the following command:
sudo apt-get -y install php-apcu
Then, restart Apache:
sudo systemctl restart apache2
Reloading the browser window with either the elastic IP address (e.g., http://44.247.136.248/info.php) or the website name (e.g., http://seattlehobbies.com/info.php) will now include PHP information about APCu.
Note: Since the ‘info.php’ displays sensitive server details about the EC2 instance, it is important to delete this file now that PHP operation is verified.
sudo rm -f /var/www/html/info.php
That’s it. The LAMP stack is installed.