A Quick Setup Guide for LEMP Stack, Laravel and Supervisord with custom AWS EC2 AMI
Are you looking to streamline the process of setting up a LEMP (Linux, Nginx, MySQL, PHP) stack for your web applications on AWS EC2? You’re in the right place! In this guide, I’ll show you how to use a custom Amazon Machine Image (AMI) that comes pre-configured with the essential components of the LEMP stack. Whether you’re a developer, a DevOps engineer, or just someone looking to save time on server setup, this guide is for you.
About the Custom AWS AMI (ami-0122ba9d1dd0d2f2e)
Before we dive into setting up your LEMP stack using this custom AMI, let’s take a moment to introduce the AMI itself and the creator behind it.
AMI ID: ami-0122ba9d1dd0d2f2e
Region: ap-northeast-1 – Asia Pacific (Tokyo)
Author: DucXinh IT
This custom AMI is crafted to include the latest versions of the components that make up the LEMP stack. It’s tailored for efficient web application development and hosting, ensuring that you have a reliable foundation for your projects.
The goal of creating this custom AMI
The goal of creating this custom AMI is to simplify and expedite the setup of LEMP stacks, empowering developers and web administrators to focus on their projects rather than infrastructure management.
Now, let’s get back to setting up your LEMP stack using this custom AMI.
Before we begin, make sure you have the following:
- An AWS account with necessary permissions.
- An EC2 instance where you want to launch the custom LEMP stack.
Step 1: Launch an EC2 Instance
- Log in to your AWS Management Console.
- Navigate to the EC2 dashboard and click on “Launch Instance.”
- Under Name and tags, for Name, enter a name to identify your instance. E.g
- Under Application and OS Images (Amazon Machine Image), for search input, enter the custom AWS AMI.
- Press Enter
- Click tab
Community AMIsand click
Selecton the first result AMI
- Under Instance type, for Instance type, select an instance type that meets your web server needs. This tutorial uses
t2.micro(Free tier eligible)
- Under Key pair (login), for Key pair name, choose your key pair. This tutorial uses
Network settings, do the following:
- Allow SSH traffic from: choose My IP
- Allow HTTPs traffic from the internet: select
- Allow HTTP traffic from the internet: select
10. In the Summary panel, review your instance configuration and then choose Launch instance.
11. Waiting ultil your instance go into the running state
12. You can see your EC2 IP: 126.96.36.199
13. Open browser and navigate to 188.8.131.52 to see the result
Step 2: Connect to the EC2 Instance
Once the instance is running, connect to it via SSH. Use the command provided by AWS with the key pair you selected.
ssh -i /path/to/your-key.pem ubuntu@your-instance-public-ip
# In this tutorial
ssh -i awesome-laravel-web.pem firstname.lastname@example.org
# If you have trouble, try to set permission to ssh file by following command:
chmod 400 awesome-laravel-web.pem
You are now connected to your EC2 instance with the custom LEMP stack.
Step 3: Verify the LEMP Stack
Check the OS version
Check the Nginx web server:
sudo systemctl status nginx
Verify PHP is installed:
Confirm MySQL is up and running:
Ensure Composer is installed:
Ensure Docker is installed:
sudo docker -v
Ensure Supervisor is up and running
sudo supervisorctl status
Step 4: Start Building Your Web Application
Now that you have a working LEMP stack, you can start developing and deploying your web applications. Simply upload your code, configure your virtual hosts in Nginx, and connect your application to the MySQL database.
- Update your code
git pull origin main
2. You can replace to your git repository and deploy your code.
## With https
git remote set-url origin https://github.com/<owner>/<repo-name>.git
git remote set-url origin https://github.com/ducxinh/laravel-sample.git
## With ssh
git remote set-url origin email@example.com:<owner>/<repo-name>.git
git remote set-url origin firstname.lastname@example.org:ducxinh/laravel-sample.git
git pull origin main
Using a custom AWS EC2 AMI can significantly reduce the time and effort required to set up a LEMP stack for your web projects. This guide has shown you how to launch an instance from a pre-configured AMI, connect to it, and confirm that the LEMP stack is ready for your web development or hosting needs.
Save time, automate your server setup, and focus on what matters most: building and deploying web applications.