Day 5 of 30 Learning AWS : LAMP & LEMP

Prajakta VadjePrajakta Vadje
6 min read

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:

  • LLinux (Operating System)

  • AApache (Web Server)

  • MMySQL (Database)

  • PPHP (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:

    • LLinux (Operating System)

    • ENginx (Web Server pronounced “Engine-X”)

    • MMySQL (Database)

    • PPHP (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:

  1. Apache/Nginx receives the request.

  2. 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:

  1. Apache (web server) receives the request.

  2. PHP runs the code to figure out what to show.

  3. MySQL is used if the page needs data (like blog posts, user info).

  4. The final web page is created and sent to the user.

  5. 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:

  1. Nginx gets the request from the browser.

  2. PHP processes the code.

  3. MySQL sends back the required data.

  4. Nginx shows the final page.

  5. Linux runs the whole system.

Installation LAMP On Amazon Linux:

  1. install httpd

  2. sudo yum update -y(update package)

  3. sudo yum install httpd -y(install httpd)

  4. sudo service httpd start(to start service)

  5. sudo service httpd status(to check status)

  6. sudo systemctl enable httpd (It enables Apache (httpd) to start automatically on system boot.)

  • install mariadb
  1. sudo yum install mariadb105-server -y (install mariadb)

  2. sudo service mariadb start(starts service)

  3. sudo service mariadb status(to check status)

  • install php
  1. sudo yum install php -y(install php)

  2. sudo service php-fpm start (start php-fpm service)

  3. sudo service php-fpm status (to check service is running or not)

  • Restart all the service
  1. sudo service nginx restart

  2. sudo service mariadb restart

  3. sudo service php-fpm restart

Installation LAMP On Ubuntu:

  1. install apache2

  2. sudo apt-get update -y(update package)

  3. sudo apt-get install apache2 -y(install apache2)

  4. sudo service apache2 start(to start service)

  5. sudo service apache2 status(to check status)

  • install mysql
  1. sudo apt-get install mysql -y (install mysql)

  2. sudo service mysql start(starts service)

  3. 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

  1. sudo service nginx restart

  2. sudo service mysql restart

  3. sudo service php8.3-fpm restart

Installation LEMP On Amazon Linux:

  1. install nginx

  2. sudo yum update -y(update package)

  3. sudo yum install nginx -y(install nginx)

  4. sudo service nginx start(to start service)

  5. sudo service nginx status(to check status)

  • install mariadb
  1. sudo yum install mariadb105-server -y (install mariadb)

  2. sudo service mariadb start(starts service)

  3. sudo service mariadb status(to check status)

  • install php
  1. sudo yum install php -y(install php)

  2. sudo service php-fpm start (start php-fpm service)

  3. sudo service php-fpm status (to check service is running or not)

  • Restart all the service
  1. sudo service nginx restart

  2. sudo service mariadb restart

  3. 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:

  1. install nginx

  2. sudo apt-get update -y(update package)

  3. sudo apt-get install nginx -y(install nginx)

  4. sudo service nginx start(to start service)

  5. sudo service nginx status(to check status)

  • install mysql
  1. sudo apt-get install mysql -y (install mysql)

  2. sudo service mysql start(starts service)

  3. 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
  1. sudo service nginx restart

  2. sudo service mysql restart

  3. 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.

1
Subscribe to my newsletter

Read articles from Prajakta Vadje directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prajakta Vadje
Prajakta Vadje