How to Set Up a LEMP Stack on Ubuntu 24.04
LEMP is Linux, Nginx, MySQL, and PHP — the standard stack for WordPress, Laravel, or any PHP web application. A clean install on Ubuntu 24.04 takes about 20 minutes. This covers everything including the PHP-FPM configuration that actually makes it work, and a test to confirm the pieces are wired together correctly before you deploy anything real.
⚡ Need a VPS? Plans from $5/mo — use code LAUNCH2026 for 50% offBefore You Start
A fresh Ubuntu 24.04 VPS with root or sudo access. The Nebula 1 plan ($5/mo) is plenty for a typical PHP application.
Step 1: Update
sudo apt update && sudo apt upgrade -y
Step 2: Install Nginx
sudo apt install nginx -y
sudo systemctl enable nginx
sudo systemctl start nginx
Open your server IP in a browser. Default Nginx page means it is working.
Step 3: Install MySQL 8.0
sudo apt install mysql-server -y
sudo systemctl enable mysql
sudo systemctl start mysql
sudo mysql_secure_installation
When it asks about the password validation component, I skip it (answer N) and just use a strong password. The validation plugin adds friction without much benefit in practice.
Step 4: Install PHP 8.3-FPM
PHP-FPM runs PHP as a separate service that Nginx talks to. Faster than the old module approach and easier to configure independently.
sudo apt install php8.3-fpm php8.3-mysql php8.3-curl php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-intl -y
That extension set covers most PHP applications including everything WordPress needs.
Step 5: Configure Nginx for PHP
sudo nano /etc/nginx/sites-available/default
Replace the contents with:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo nginx -t
sudo systemctl reload nginx
Step 6: Test PHP
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/test.php
Visit http://your-server-ip/test.php. You should see the PHP 8.3 info page with FPM/FastCGI listed as the server API. If you get a blank page or a file download, the FPM socket path in the Nginx config does not match what PHP-FPM actually created — check /var/run/php/ to see what socket name it made.
Step 7: Remove the Test File
sudo rm /var/www/html/test.php
The phpinfo page exposes server details publicly. Delete it before you forget.
Create a Database
sudo mysql -u root -p
CREATE DATABASE myapp;
CREATE USER 'myappuser'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON myapp.* TO 'myappuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Optional: Add SSL
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com
Stack is ready. Drop your app into /var/www/html or create new server blocks in /etc/nginx/sites-available/ for multiple sites.
Fresh Ubuntu 24.04 VPS from $5/mo
Full root access, KVM virtualization, Cloudflare DDoS protection. Use code LAUNCH2026 for 50% off your first month.
Get Started