βœ… Day 17 of My Cloud Journey β€” LAMP vs LEMP Stack on AWS EC2 πŸš€

Pratik DasPratik Das
3 min read

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)

  1. Launched EC2 Instances (Amazon Linux 2 or Ubuntu)

  2. Placed them in a public subnet

  3. Allowed traffic in Security Groups:

    • Port 22 (SSH)

    • Port 80 (HTTP)

  4. Connected via SSH to install necessary software


πŸ”§ Part 1: Setting Up LAMP Stack (Apache)

βœ… Steps:

  1. Install Apache:

     sudo yum install httpd -y
     sudo systemctl enable httpd
     sudo systemctl start httpd
    
  2. Install PHP:

     sudo yum enable php8.2
     sudo yum install php php-mysqlnd -y
    
  3. Test PHP:

     echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
    
  4. Install MariaDB (MySQL):

     sudo yum install mariadb105-server -y
     sudo systemctl start mariadb
     sudo systemctl enable mariadb
    
  5. 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:

  1. Install NGINX:

    
     sudo yum install nginx -y
     sudo systemctl enable nginx
     sudo systemctl start nginx
    
  2. Install PHP + PHP-FPM:

    
     sudo yum install php php-fpm php-mysqlnd -y
    
  3. Configure PHP-FPM:
    Edit /etc/php-fpm.d/www.conf:

     user = nginx
     group = nginx
    
  4. 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;
     }
    
  5. Restart Services:

     sudo systemctl restart php-fpm
     sudo systemctl restart nginx
    
  6. 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

FeatureLAMP (Apache)LEMP (NGINX)
Web ServerApacheNGINX
PHP Integrationmod_phpphp-fpm
PerformanceSlower under loadFaster, async
ConfigurationEasier for beginnersSlightly advanced
Use CaseLegacy systems, WordPressModern 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

0
Subscribe to my newsletter

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

Written by

Pratik Das
Pratik Das