If you want to host dynamic PHP websites or applications like WordPress, Laravel, or Magento, learning how to install LEMP Stack on Ubuntu is one of the first steps. The LEMP stack combines Linux, Nginx, MySQL, and PHP to create a powerful and high-performance web hosting environment.
Ubuntu 26.04 makes deploying the LEMP stack easier with updated repositories and improved package support. This guide walks through the complete installation and configuration process.
What Is a LEMP Stack?
LEMP stands for:
- Linux operating system
- Nginx web server
- MySQL database server
- PHP processing engine
Together, these components allow Ubuntu servers to handle dynamic websites, APIs, and modern web applications efficiently.
Install Nginx on Ubuntu 26.04
Start by updating the package index:
sudo apt update
Install Nginx:
sudo apt install nginx
After installation, verify that the service is running:
sudo systemctl status nginx
If the firewall is enabled, allow web traffic:
sudo ufw allow 'Nginx Full'
You can now open your server IP address in a browser to confirm Nginx is working.
Install MySQL Database Server
MySQL stores application data and user information for websites and PHP applications.
Install MySQL using:
sudo apt install mysql-server
Run the security script to harden the database configuration:
sudo mysql_secure_installation
This helps remove insecure defaults and improves database security.
Check the service status:
sudo systemctl status mysql
Install LEMP Stack PHP Components
Nginx does not process PHP directly, so Ubuntu uses PHP-FPM for handling PHP requests.
Install PHP and required MySQL extensions:
sudo apt install php-fpm php-mysql
Verify the PHP version:
php -v
Ubuntu 26.04 installs PHP 8.5 by default.
For additional PHP features, you can also install common extensions:
sudo apt install php-curl php-gd php-mbstring php-xml php-zip
Configure Nginx for PHP
Create a directory for your website:
sudo mkdir -p /var/www/example.com
Create a new Nginx server block:
sudo nano /etc/nginx/sites-available/example.com
Add a PHP configuration that forwards .php requests to PHP-FPM using the Unix socket.
After saving the file, enable the configuration:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Test the configuration:
sudo nginx -t
Reload Nginx:
sudo systemctl reload nginx
Test PHP Processing
Create a simple PHP info page:
echo "<?php phpinfo();" | sudo tee /var/www/example.com/info.php
Visit the page in your browser to verify PHP is processing correctly through Nginx and PHP-FPM.
After testing, remove the file for security reasons:
sudo rm /var/www/example.com/info.php
Final Thoughts
Learning how to install LEMP Stack on Ubuntu 26.04 gives you a strong foundation for hosting PHP applications and modern websites. With Nginx handling web traffic, MySQL managing databases, and PHP-FPM processing scripts efficiently, the LEMP stack remains one of the most reliable Linux web server environments available today.
Once your stack is working, you can continue by installing SSL certificates, deploying WordPress, or configuring multiple Nginx virtual hosts.
.webp)