Day 5 of 30 Learning AWS : LAMP & LEMP

Earlier we learned about Nginx and Apache. In this blog we’ll learn how to use them to create a full stack environment for running web applications.
LAMP and LEMP are software stacks that help run websites by combining a server, a database, and a scripting language the only difference is the web server
Apache (LAMP) and Nginx (LEMP).
What is LAMP?
LAMP is a set of open-source software used to run websites and web applications
It stands for:
L – Linux (Operating System)
A – Apache (Web Server)
M – MySQL (Database)
P – PHP (Programming Language)
LAMP is like a team that works together to run a website:
Linux is the foundation (like your computer’s system),
Apache shows your website to people,
MySQL stores the data (like users, posts),
PHP makes the site work (like login, display posts, etc.)
What is LEMP?
LEMP is very similar to LAMP but it uses Nginx instead of Apache
It stands for:
L – Linux (Operating System)
E – Nginx (Web Server pronounced “Engine-X”)
M – MySQL (Database)
P – PHP (Programming Language)
LEMP works the same way as LAMP but uses Nginx instead of Apache. Nginx is known to be faster and lighter than Apache, especially for high traffic websites.it delivers the content faster
Why Do We Use LAMP and LEMP Stack?
We use LAMP or LEMP to host and run dynamic websites or web applications.
They provide everything needed to:
Store website data (like users, posts)
Process code (like PHP)
Show web pages in a browser
Think of it like building a house:
Linux is the land (foundation)
Apache/Nginx is the door (lets visitors in)
MySQL is the storage room (holds your stuff)
PHP is the worker (gets things done)
Real-Life Example (Blog Website)
You want to create a blog where:
People can read posts
You can log in and add new posts
Using LAMP or LEMP:
Linux: Runs your server (like Ubuntu on AWS EC2)
Apache/Nginx: Shows the blog pages when someone visits
MySQL: Stores all blog posts, usernames, and passwords
PHP: Writes the logic (like login, show posts, etc.)
So when a user visits yourblog.com:
Apache/Nginx receives the request.
PHP runs the code and gets blog posts from MySQL.
Apache/Nginx sends the page to the user’s browser.
How LAMP Works (Linux, Apache, MySQL, PHP)
When someone opens your website in a browser:
Apache (web server) receives the request.
PHP runs the code to figure out what to show.
MySQL is used if the page needs data (like blog posts, user info).
The final web page is created and sent to the user.
Linux runs everything behind the scenes (the operating system).
How LEMP Works (Linux, Nginx, MySQL, PHP)
It works the same way, but instead of Apache, it uses Nginx:
Nginx gets the request from the browser.
PHP processes the code.
MySQL sends back the required data.
Nginx shows the final page.
Linux runs the whole system.
Installation LAMP On Amazon Linux:
install httpd
sudo yum update -y(update package)
sudo yum install httpd -y(install httpd)
sudo service httpd start(to start service)
sudo service httpd status(to check status)
sudo systemctl enable httpd (It enables Apache (httpd) to start automatically on system boot.)
- install mariadb
sudo yum install mariadb105-server -y (install mariadb)
sudo service mariadb start(starts service)
sudo service mariadb status(to check status)
- install php
sudo yum install php -y(install php)
sudo service php-fpm start (start php-fpm service)
sudo service php-fpm status (to check service is running or not)
- Restart all the service
sudo service nginx restart
sudo service mariadb restart
sudo service php-fpm restart
Installation LAMP On Ubuntu:
install apache2
sudo apt-get update -y(update package)
sudo apt-get install apache2 -y(install apache2)
sudo service apache2 start(to start service)
sudo service apache2 status(to check status)
- install mysql
sudo apt-get install mysql -y (install mysql)
sudo service mysql start(starts service)
sudo service mysql status(to check status)
install php
sudo apt-get install php -y(install php)
php-v (check version first then start php service)
sudo service php8.3-fpm start (to start the service)
sudo service php8.3-fpm status (to check status)
Restart all the service
sudo service nginx restart
sudo service mysql restart
sudo service php8.3-fpm restart
Installation LEMP On Amazon Linux:
install nginx
sudo yum update -y(update package)
sudo yum install nginx -y(install nginx)
sudo service nginx start(to start service)
sudo service nginx status(to check status)
- install mariadb
sudo yum install mariadb105-server -y (install mariadb)
sudo service mariadb start(starts service)
sudo service mariadb status(to check status)
- install php
sudo yum install php -y(install php)
sudo service php-fpm start (start php-fpm service)
sudo service php-fpm status (to check service is running or not)
- Restart all the service
sudo service nginx restart
sudo service mariadb restart
sudo service php-fpm restart
Edit the default site config:
sudo nano /etc/nginx/nginx.conf
Inside the server
block add or modify:(uncomment these lines to run php)
index index.php index.html;
location ~ .php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; }
Installation LEMP On Ubuntu:
install nginx
sudo apt-get update -y(update package)
sudo apt-get install nginx -y(install nginx)
sudo service nginx start(to start service)
sudo service nginx status(to check status)
- install mysql
sudo apt-get install mysql -y (install mysql)
sudo service mysql start(starts service)
sudo service mysql status(to check status)
install php
sudo apt-get install php php-fpm -y(install php)
php-v (check version first then start php service)
sudo service php8.3-fpm start (to start the service)
sudo service php8.3-fpm status (to check status)
Edit the default server config:
sudo nano /etc/nginx/sites-available/default
Update or ensure these lines exist:
index index.php index.html index.html;
location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock; }
- Restart all the service
sudo service nginx restart
sudo service mysql restart
sudo service php8.3-fpm restart
As part of installing the LEMP stack on Amazon Linux, I’ll demonstrate how to test if PHP is working by creating and running a sample PHP file through the Nginx web server.
install all the service
start all the services
now paste your instance ip on browser to check nginx is working or not
go to html directory and create file.php to check php is running or not
folder path:
cd /usr/share/nginx/html
check now php is running or not
as you can see php is successfully running
Conclusion
As part of setting up the LEMP stack on Amazon Linux, I successfully demonstrated how to check if PHP is working by creating a sample PHP file and running it through the Nginx web server. This confirms that Nginx, PHP, and MySQL are correctly installed and ready to host dynamic websites or applications.
Subscribe to my newsletter
Read articles from Prajakta Vadje directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
