AWS — How to Host a LAMP Web Application Server on AWS EC2 For Free

Shawn Shi
4 min readJun 14, 2018

UPDATED 2020/10/16:
- I walked through this exercise again.
- All of the screenshots have been updated so that this article is accurate for the new EC2 experience in 2020!
- All commands have been updated so that newer versions of MySQL and PHP are installed.

Amazon Web Services (AWS) is by far the best cloud service on the market. Its free tier allows everyone to run EC2 instances for up to 750hours per month, which means we can host a web application server for free! This article covers how to quickly launch an EC2 instance and have LAMP (Linux, Apache, MySQL and PHP) automatically pre-installed.

Step 1 — Login to your AWS Console (you need to register for AWS account if you don’t have one yet)

Screenshot by Author

Step 2 — Launch an EC2 instance

Screenshot by Author

Search for Linux AMI and Select the Amazon Linux AMI Image

Screenshot by Author
Screenshot by Author

At section “3: Configure Instance Details”, look for Advanced Details and enter the following code in the “User data” part. Please note that as of 2020/10/16, the following code has been updated for newer versions of MySQL and PHP.

sudo yum update -y
sudo yum install -y httpd24 php72 mysql57-server php72-mysqlnd
sudo service httpd start
sudo chkconfig httpd on
sudo usermod -a -G apache ec2-user
sudo chown -R ec2-user:apache /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \; find /var/www -type f -exec sudo chmod 0664 {} \;
echo “<?php phpinfo(); ?>” > /var/www/html/phpinfo.php
Screenshot by Author

Keep clicking “Next” until you get to “Step 6: Configure Security Group”, add rules…

Shawn Shi

Senior Software Engineer at Microsoft. Ex-Machine Learning Engineer. When I am not building applications, I am playing with my kids or outside rock climbing!