A LEMP stack is the modern foundation for hosting dynamic websites — WordPress, Laravel apps, custom PHP, you name it. It stands for Linux, Engine-x (Nginx), MySQL/MariaDB, and PHP. This guide gets you from a fresh Ubuntu 24.04 server to a working stack. You will want a Linux VPS with root access and a domain pointed at it (see how to point a domain to a VPS).
1. Update the server
Always start fresh: sudo apt update && sudo apt upgrade -y.
2. Install Nginx
sudo apt install nginx -y, then sudo systemctl enable --now nginx. Visit your server's IP in a browser and you should see the Nginx welcome page. If not, make sure ports 80/443 are open — you can check from outside with our port checker.
3. Install the database
Install MariaDB (a drop-in MySQL replacement) with sudo apt install mariadb-server -y, then run sudo mysql_secure_installation and answer the prompts to set a root password, remove anonymous users, and disable remote root login. This step matters — an open database is a common cause of breaches.
4. Install PHP-FPM
Nginx does not run PHP itself; it hands PHP requests to PHP-FPM. Install it with sudo apt install php-fpm php-mysql -y, plus any extensions your app needs (e.g. php-curl php-gd php-mbstring).
5. Tell Nginx to use PHP
Create a server block for your site in /etc/nginx/sites-available/, set the root to your web directory, add index.php to the index list, and add a location ~ \.php$ block that passes requests to the PHP-FPM socket. Enable the site, test the config with sudo nginx -t, and reload with sudo systemctl reload nginx.
6. Test it
Drop a file with <?php phpinfo(); ?> into your web root and load it in a browser. If you see the PHP info page, the whole stack is talking to itself. Delete that file afterward — it exposes server details.
7. Go to production
Before real traffic, add a free Let's Encrypt SSL certificate with certbot and verify it with our SSL checker. Then harden the server with our security checklist.
What's next
With LEMP running you can install almost any PHP app. The obvious next step is installing WordPress. Curious why we chose Nginx? Read Nginx vs Apache.