How to Install LEMP Stack on DigitalOcean Droplet 2026
Linux · Nginx · MySQL/MariaDB · PHP-FPM — the full production-ready setup on Ubuntu 24.04
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.
Table of Contents
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
php8.3-mysql— MySQL/MariaDB connectivityphp8.3-xml,php8.3-mbstring— required by WordPress corephp8.3-gd— image processing for resizing uploadsphp8.3-bcmath— arbitrary precision math (WooCommerce, payment gateways)
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
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.
- Install
wp-clito manage WordPress from the command line (faster than the browser UI) - Increase PHP upload limits in
/etc/php/8.3/fpm/php.ini:upload_max_filesize = 64M,post_max_size = 64M - Enable PHP OPcache (
opcache.enable=1) for significant performance improvement - Use
mariadb-optimizeormysqltunerto tune database memory settings per available RAM
Get DigitalOcean + $200 Free Credit →