β Day 17 of My Cloud Journey β LAMP vs LEMP Stack on AWS EC2 π

Today, I dove deep into two foundational stacks used for hosting dynamic web applications:
πΉ LAMP: Linux, Apache, MySQL, PHP
πΉ LEMP: Linux, NGINX, MySQL, PHP (pronounced "Engine-X")
The goal was to install and configure both stacks on separate EC2 instances and understand their internal workings.
ποΈ Infrastructure Setup (Same for Both)
Launched EC2 Instances (Amazon Linux 2 or Ubuntu)
Placed them in a public subnet
Allowed traffic in Security Groups:
Port 22 (SSH)
Port 80 (HTTP)
Connected via SSH to install necessary software
π§ Part 1: Setting Up LAMP Stack (Apache)
β Steps:
Install Apache:
sudo yum install httpd -y sudo systemctl enable httpd sudo systemctl start httpd
Install PHP:
sudo yum enable php8.2 sudo yum install php php-mysqlnd -y
Test PHP:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Install MariaDB (MySQL):
sudo yum install mariadb105-server -y sudo systemctl start mariadb sudo systemctl enable mariadb
Secure MySQL (Optional):
sudo mysql_secure_installation
β
Apache will serve content from /var/www/html/
β
PHP works seamlessly with Apache via mod_php
β‘ Part 2: Setting Up LEMP Stack (NGINX)
β Steps:
Install NGINX:
sudo yum install nginx -y sudo systemctl enable nginx sudo systemctl start nginx
Install PHP + PHP-FPM:
sudo yum install php php-fpm php-mysqlnd -y
Configure PHP-FPM:
Edit/etc/php-fpm.d/www.conf
:user = nginx group = nginx
Configure NGINX for PHP:
Edit/etc/nginx/nginx.conf
or create a server block:location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
Restart Services:
sudo systemctl restart php-fpm sudo systemctl restart nginx
Test PHP:
echo "<?php phpinfo(); ?>" | sudo tee /usr/share/nginx/html/info.php
β
NGINX will serve content from /usr/share/nginx/html/
β
PHP is handled more efficiently via php-fpm
π LAMP vs LEMP β Key Differences
Feature | LAMP (Apache) | LEMP (NGINX) |
Web Server | Apache | NGINX |
PHP Integration | mod_php | php-fpm |
Performance | Slower under load | Faster, async |
Configuration | Easier for beginners | Slightly advanced |
Use Case | Legacy systems, WordPress | Modern apps, APIs |
π§ What I Learned
How to install and configure both Apache and NGINX
PHP integration differences between mod_php and php-fpm
NGINXβs performance advantage and static file handling
MySQL basic management (starting/stopping services)
File structure and config files of both servers
π Why This Matters
Before jumping into WordPress or frameworks like Laravel, itβs crucial to know how web servers and databases interact.
LAMP/LEMP form the foundation of web hosting β locally or on the cloud.
π Whatβs Next?
Day 18 β Mastering MySQL for Dynamic Websites π οΈ
Now that I understand LAMP & LEMP stacks, it's time to dive into MySQL, the backbone of dynamic web applications.
Tomorrow, Iβll be learning:
πΉ How to create a MySQL database and user
πΉ Writing basic queries:
CREATE
,INSERT
,SELECT
,UPDATE
,DELETE
πΉ Understanding tables, relationships, and normalization
πΉ Connecting MySQL to a web server (Apache/NGINX)
π― This is essential prep for upcoming projects like:
Hosting WordPress manually on EC2
Running dynamic apps with PHP + MySQL
Migrating to managed services like Amazon RDS
Subscribe to my newsletter
Read articles from Pratik Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
