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.
मित्रांनो, LEMP मध्ये Apache च्या जागी Nginx येतो, आणि PHP वेगळ्या PHP-FPM सर्व्हिसमध्ये चालतो. डेटाबेस आणि PHP कोड तसेच राहतात.
दोस्तों, LEMP में Apache की जगह Nginx आता है, और PHP अलग PHP-FPM सर्विस में चलता है. डेटाबेस और PHP कोड वैसे ही रहते हैं.
+------------------ 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.
Ravindra Bagale's Tip – मराठी
खूप students test नंतर info.php server वर तसाच ठेवतात. ते page PHP version, paths आणि settings सगळ्यांना दाखवतं. grep -m1 "PHP Version" ने test झाला की लगेच sudo rm ने file काढा.
Ravindra Bagale's Tip – हिंदी
बहुत students test के बाद info.php server पर वैसे ही छोड़ देते हैं. वो page PHP version, paths और settings सबको दिखाता है. grep -m1 "PHP Version" से test हो गया तो तुरंत sudo rm से file हटाओ.
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.
समजलं का? LAMP आणि LEMP मध्ये फरक फक्त वेब सर्व्हरचा – Apache की Nginx. PHP आणि डेटाबेस तेच राहतात. आता पुढे जाऊया JavaScript स्टॅक्सकडे – MEAN आणि MERN.
समझ आया? LAMP और LEMP में फ़र्क सिर्फ़ वेब सर्वर का है – Apache या Nginx. PHP और डेटाबेस वही रहते हैं. अब आगे चलते हैं JavaScript स्टैक्स की तरफ़ – MEAN और MERN.