This site contains affiliate links — we may earn a commission if you sign up. Affiliate links.

How to Install LEMP Stack on DigitalOcean Droplet 2026

Linux · Nginx · MySQL/MariaDB · PHP-FPM — the full production-ready setup on Ubuntu 24.04

How to Install LEMP Stack on DigitalOcean Droplet 2026

The LEMP Stack — Linux, Nginx, MySQL (or MariaDB), and PHP-FPM — is one of the most popular server setups for PHP-based websites including WordPress. This guide walks you through every command to get a fully functional LEMP Stack running on a DigitalOcean Droplet (Ubuntu 24.04 LTS), with Nginx Virtual Hosts and free SSL from Let's Encrypt, in about 30 minutes.

Prepare Your Droplet

Create a Droplet with Ubuntu 24.04 LTS. The Basic 1 GiB RAM / 1 vCPU / 25 GB SSD plan at $6/month is enough for small-to-medium PHP sites. Choose the Singapore or Bangalore region for lowest latency from Southeast Asia. SSH in and update the system first.

apt update && apt upgrade -y
adduser deploy && usermod -aG sudo deploy

Install Nginx

Nginx serves static content efficiently and proxies PHP requests to PHP-FPM. It uses an event-driven, asynchronous architecture that handles thousands of concurrent connections with minimal memory.

apt install nginx -y
systemctl enable nginx
systemctl start nginx
ufw allow 'Nginx Full'
ufw enable

Visit http://<Droplet-IP> — you should see the "Welcome to nginx!" page confirming Nginx is running.

Install MySQL / MariaDB

MariaDB is a fully compatible MySQL replacement with faster releases and easier Ubuntu installation. Run the security script to set a root password, remove test databases, and disable anonymous access.

apt install mariadb-server -y
systemctl enable mariadb
mysql_secure_installation

Create a dedicated database and user for each application — never use the root account for your apps:

mysql -u root -p
CREATE DATABASE mysite CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'SecurePassword!';
GRANT ALL PRIVILEGES ON mysite.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Install PHP-FPM

Nginx passes PHP requests to PHP-FPM (FastCGI Process Manager) over a Unix socket. Install PHP 8.3 with common extensions for WordPress and general PHP applications.

apt install php8.3-fpm php8.3-mysql php8.3-xml php8.3-mbstring php8.3-curl php8.3-zip php8.3-gd php8.3-bcmath -y
systemctl enable php8.3-fpm
systemctl start php8.3-fpm

Configure Nginx Virtual Host

Create a server block for your domain. Each domain or subdomain gets its own config file in /etc/nginx/sites-available/.

nano /etc/nginx/sites-available/mysite.com

Paste this configuration:

server {
    listen 80;
    server_name mysite.com www.mysite.com;
    root /var/www/mysite.com;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }
}
mkdir -p /var/www/mysite.com
chown -R www-data:www-data /var/www/mysite.com
ln -s /etc/nginx/sites-available/mysite.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

Test PHP

Create a temporary PHP info file to verify that Nginx is correctly passing requests to PHP-FPM. Delete it immediately after testing — it exposes your PHP version and server configuration.

echo "<?php phpinfo(); ?>" > /var/www/mysite.com/info.php

Open http://mysite.com/info.php. You should see the purple PHP Information page confirming PHP 8.3 is active.

rm /var/www/mysite.com/info.php

Enable SSL with Let's Encrypt

Certbot automatically obtains and renews free 90-day SSL certificates from Let's Encrypt. Your domain's DNS A record must point to the Droplet IP before running Certbot.

apt install certbot python3-certbot-nginx -y
certbot --nginx -d mysite.com -d www.mysite.com

Certbot will modify your Nginx config to add HTTPS and set up an automatic redirect from HTTP to HTTPS. Verify auto-renewal works:

certbot renew --dry-run
Important: Keep port 80 open permanently — Let's Encrypt uses HTTP-01 challenge over port 80 for automated renewals. Blocking port 80 will cause certificate expiration.

Deploy WordPress on LEMP

With LEMP in place, deploying WordPress takes just a few commands:

cd /var/www/mysite.com
wget https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz --strip-components=1
chown -R www-data:www-data .
cp wp-config-sample.php wp-config.php
nano wp-config.php

Set DB_NAME, DB_USER, DB_PASSWORD to the values you created in MariaDB. Then visit https://mysite.com to run the WordPress installation wizard.

Get DigitalOcean + $200 Free Credit →

Frequently Asked Questions

What is the difference between LEMP and LAMP stack?
LAMP uses Apache as the web server; LEMP uses Nginx (the E comes from engine-x). Nginx handles static files more efficiently and serves high concurrent connections with less memory — better suited for smaller Droplets.
Why is PHP-FPM needed with Nginx?
Unlike Apache, Nginx cannot execute PHP natively. PHP-FPM (FastCGI Process Manager) acts as a bridge between Nginx and PHP, processing PHP requests via the FastCGI protocol.
Which Droplet size is right for LEMP Stack?
For WordPress or small-to-medium PHP sites, a Basic Droplet with 1 GiB RAM / 1 vCPU / 25 GB SSD ($6/month) is sufficient. For higher traffic or multiple sites, 2 GiB RAM / 2 vCPU ($18/month) is recommended.
Should I use MySQL or MariaDB?
Both work identically for most use cases. MariaDB is a community-driven MySQL fork with near-100% SQL compatibility, faster release cycles, and easier installation on Ubuntu via apt.
Can I host multiple websites on one Droplet with LEMP?
Yes. Create separate Nginx server blocks (Virtual Hosts) per domain, each pointing to a different root directory. Certbot can issue individual SSL certificates per domain as well.