Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 12: Technology Stacks — LAMP, LEMP, MEAN, MERN

12.3 LEMP stack

Friends, in LEMP Nginx takes Apache's place, and PHP runs in a separate PHP-FPM service. The database and PHP code stay the same.

                        +------------------ EC2 (Linux) -------------------+
  Browser ──HTTP:80──►  |  Nginx ──FastCGI (unix socket)──► PHP-FPM        |
                        |    static files served directly      │           |
                        |                                      ▼           |
                        |                            MySQL/MariaDB :3306   |
                        +--------------------------------------------------+

Full LEMP installation

Amazon Linux 2023 (default Nginx server already handles .php via /etc/nginx/default.d/php.conf):

sudo yum install -y nginx php php-fpm php-mysqlnd php-gd php-mbstring php-xml mariadb105-server
sudo service nginx start
sudo service php-fpm start
sudo service mariadb start
sudo systemctl enable nginx php-fpm mariadb
sudo mysql_secure_installation
echo "<?php phpinfo();" | sudo tee /usr/share/nginx/html/info.php
curl -s http://localhost/info.php | grep -m1 "PHP Version"

Ubuntu:

sudo apt update
sudo apt install -y nginx mysql-server php-fpm php-mysql php-gd php-mbstring php-xml
sudo service nginx start
sudo service mysql start
sudo systemctl enable nginx mysql
sudo mysql_secure_installation

Then enable PHP in the Ubuntu default site — edit /etc/nginx/sites-available/default: add index.php to the index line and un-comment the PHP block so it reads:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php-fpm.sock;
}
sudo nginx -t && sudo service nginx reload
echo "<?php phpinfo();" | sudo tee /var/www/html/info.php
curl -s http://localhost/info.php | grep -m1 "PHP Version"

CentOS Stream 9:

sudo yum install -y nginx php php-fpm php-mysqlnd php-gd php-mbstring php-xml mariadb-server
sudo service nginx start
sudo service php-fpm start
sudo service mariadb start
sudo systemctl enable nginx php-fpm mariadb
sudo mysql_secure_installation
echo "<?php phpinfo();" | sudo tee /usr/share/nginx/html/info.php
sudo restorecon -Rv /usr/share/nginx/html
curl -s http://localhost/info.php | grep -m1 "PHP Version"

Remove info.php after testing: sudo rm /usr/share/nginx/html/info.php (or /var/www/html/info.php on Ubuntu).

Ravindra Bagale's Tip

Many students leave info.php on the server after testing. That page shows your PHP version, paths and settings to everyone. Once the test with grep -m1 "PHP Version" passes, remove the file right away with sudo rm.

Lab

Chala, Ubuntu var LEMP install kara aani default site madhe PHP block un-comment kara. sudo nginx -t && sudo service nginx reload nantar curl -s http://localhost/info.php | grep -m1 "PHP Version" chalva, aani mag info.php kadhun taka.

Got it? The only difference between LAMP and LEMP is the web server – Apache or Nginx. PHP and the database stay the same. Now let's move on to the JavaScript stacks – MEAN and MERN.