This article may contain affiliate links — we earn a commission if you purchase through them at no extra cost to you. Editorial Policy

VPS & Server Guide

Install LEMP Stack on VPS [2026]
Complete Guide — Linux + Nginx + MariaDB + PHP

By CloudPicked Review Team  ·  Last updated October 2026

LEMP Stack installation on VPS — Linux Nginx MariaDB PHP

The LEMP Stack is a foundational set of open-source software used to deploy websites and web applications on Linux VPS servers. It comprises Linux (operating system), Enginx (web server), MariaDB/MySQL (database), and PHP (server-side language). Together they form a complete, production-ready web environment.

In 2026, LEMP remains the go-to server stack for developers who need speed, reliability, and efficient resource usage. Nginx's event-driven architecture makes it particularly well-suited for VPS instances with limited RAM, handling thousands of concurrent connections with minimal overhead.

Table of Contents

  1. What is LEMP Stack?
  2. LEMP vs LAMP — Which Should You Choose?
  3. VPS Requirements and Prerequisites
  4. Step 1 — Update Ubuntu
  5. Step 2 — Install Nginx
  6. Step 3 — Install MariaDB
  7. Step 4 — Install PHP-FPM
  8. Step 5 — Configure Nginx Virtual Host
  9. Step 6 — Test PHP and Database
  10. Step 7 — Install WordPress on LEMP
  11. Security Hardening
  12. Performance Tuning
  13. Frequently Asked Questions

What is LEMP Stack?

The acronym LEMP stands for the four core components:

Each component runs as an independent service, making updates and replacements easy. In practice, Nginx receives HTTP requests from browsers, serves static files directly, and passes PHP requests to PHP-FPM (a separate process manager). PHP-FPM executes the PHP code (which may query MariaDB), and the resulting HTML is returned to Nginx and sent back to the browser.

LEMP vs LAMP — Which Should You Choose?

The only architectural difference between LEMP and LAMP is the web server component. Here's how they compare:

Feature LEMP (Nginx) LAMP (Apache)
ArchitectureEvent-driven (asynchronous)Process/thread-based
Memory UsageLower (handles concurrency efficiently)Higher per connection
Concurrent ConnectionsExcellent (thousands with low RAM)Limited by process count
Static File ServingVery fastGood
.htaccess SupportNot supported (use nginx.conf)Supported
PHP ExecutionVia PHP-FPM onlyVia mod_php or PHP-FPM
Config FlexibilityNginx server blocks.htaccess per-directory
Best ForHigh traffic, RAM-constrained VPSShared hosting, simple setups

Data as of October 2026 — benchmark results may vary by version and workload

For most VPS deployments, LEMP delivers better performance because Nginx uses an event-driven architecture to handle thousands of requests simultaneously with minimal thread overhead. This is especially valuable on VPS instances with 1-2GB RAM.

When to choose LAMP instead: If you rely heavily on .htaccess rules (complex redirect rules, per-directory configs), or use cPanel which is built around Apache, LAMP may be more convenient. Nginx requires .htaccess rules to be manually translated into nginx.conf directives.

VPS Requirements and Prerequisites

Before starting the installation, ensure you have the following:

VPS Recommendation: For Thailand-based projects, AsiaGB offers VPS in Thailand and Singapore with Thai-language support. Ruk-Com Cloud is another solid choice with local Thai support.

1

Update Ubuntu Before Starting

Connect to your VPS via SSH and update all packages first. This ensures you install the latest versions and reduces security exposure:

sudo apt update && sudo apt upgrade -y

This command refreshes the package index and upgrades all installed packages. It may take a few minutes depending on how many updates are pending.

2

Install Nginx

Nginx is available in Ubuntu's default repository and installs cleanly with a single command:

sudo apt install nginx -y

Enable Nginx to start on boot and verify it's running:

sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx

If you see Active: active (running), Nginx is working. Test by opening a browser to http://YOUR_SERVER_IP — you should see the "Welcome to nginx!" page.

Configure UFW Firewall

If UFW firewall is active, allow HTTP and HTTPS traffic:

sudo ufw allow 'Nginx Full'
sudo ufw status
3

Install MariaDB

MariaDB is a fully compatible MySQL replacement with excellent performance. We recommend MariaDB 10.11 LTS (Long Term Support until 2028):

sudo apt install mariadb-server mariadb-client -y
sudo systemctl enable mariadb
sudo systemctl start mariadb

Run Security Hardening

Always run the built-in security script immediately after installation:

sudo mysql_secure_installation

Answer the prompts as follows:

Create a Database and User

Create a dedicated database and user for each website (never use root for applications):

sudo mysql -u root -p
CREATE DATABASE mywebsite_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'mywebsite_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON mywebsite_db.* TO 'mywebsite_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
4

Install PHP-FPM

Unlike Apache, Nginx doesn't have a built-in PHP module. Instead, it communicates with PHP-FPM (FastCGI Process Manager), which runs PHP as a separate service and listens on a Unix socket.

PHP Version Recommendations (October 2026)

Verify the latest support timeline at php.net/supported-versions.php

Install PHP 8.3

On Ubuntu 22.04, add the Ondřej Surý PPA first (provides newer PHP versions than Ubuntu's default repo):

sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

Install PHP-FPM and common extensions:

sudo apt install php8.3-fpm php8.3-mysql php8.3-xml php8.3-curl php8.3-mbstring php8.3-zip php8.3-intl php8.3-gd php8.3-bcmath php8.3-imagick -y

Enable and start PHP-FPM:

sudo systemctl enable php8.3-fpm
sudo systemctl start php8.3-fpm
sudo systemctl status php8.3-fpm

Additional Extensions for WordPress

sudo apt install php8.3-opcache php8.3-redis php8.3-soap -y
5

Configure Nginx Virtual Host

Create a server block configuration file for your website:

sudo nano /etc/nginx/sites-available/yourdomain.com

Paste the following configuration (replace yourdomain.com with your actual domain):

server {
    listen 80;
    listen [::]:80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/yourdomain.com;
    index index.php index.html;

    # Static file caching
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2)$ {
        expires 30d;
        add_header Cache-Control "public, no-transform";
    }

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
    add_header X-XSS-Protection "1; mode=block";
}

Enable the Virtual Host

sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Always run nginx -t to test your configuration syntax before reloading. A typo in the config can take down your entire server.

Create the Document Root

sudo mkdir -p /var/www/yourdomain.com
sudo chown -R www-data:www-data /var/www/yourdomain.com
sudo chmod -R 755 /var/www/yourdomain.com
6

Test PHP and Database Connection

Create a PHP info file to verify PHP-FPM is working correctly with Nginx:

sudo nano /var/www/yourdomain.com/info.php
<?php phpinfo(); ?>

Navigate to http://yourdomain.com/info.php in a browser. If you see the PHP information page with server details, your LEMP stack is working.

Security Notice: Remove info.php immediately after testing. This file exposes server configuration that could aid attackers.

sudo rm /var/www/yourdomain.com/info.php

Test Database Connectivity

<?php
$conn = new mysqli('localhost', 'mywebsite_user', 'StrongPassword123!', 'mywebsite_db');
if ($conn->connect_error) {
    die('Connection failed: ' . $conn->connect_error);
}
echo 'Connected successfully to MariaDB!';
$conn->close();
?>
7

Install WordPress on LEMP Stack

WordPress runs excellently on LEMP. Here's a streamlined installation process:

Download and Extract WordPress

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzf latest.tar.gz
sudo cp -r wordpress/* /var/www/yourdomain.com/
sudo chown -R www-data:www-data /var/www/yourdomain.com/
sudo chmod -R 755 /var/www/yourdomain.com/

Configure wp-config.php

cd /var/www/yourdomain.com
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update the database connection settings:

define('DB_NAME', 'mywebsite_db');
define('DB_USER', 'mywebsite_user');
define('DB_PASSWORD', 'StrongPassword123!');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8mb4');

WordPress-Specific Nginx Configuration

WordPress requires the try_files directive and uploads protection:

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

# Block PHP execution in uploads directory
location ~* /(?:uploads|files)/.*\.php$ {
    deny all;
}

Install SSL Certificate (Let's Encrypt)

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot automatically configures HTTPS and sets up HTTP-to-HTTPS redirects. Certificates renew automatically every 90 days.

Security Hardening

A basic LEMP installation is functional but needs additional hardening for production use:

1. Disable Root SSH and Use Key-Based Auth

sudo nano /etc/ssh/sshd_config
# Modify these lines:
Port 2222
PasswordAuthentication no
PermitRootLogin no

2. Install Fail2Ban

sudo apt install fail2ban -y
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

3. Hide Nginx Version

In /etc/nginx/nginx.conf, within the http block:

server_tokens off;

4. Tune PHP-FPM Process Manager

Edit /etc/php/8.3/fpm/pool.d/www.conf:

pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 3
pm.max_spare_servers = 7

5. Harden PHP Settings

sudo nano /etc/php/8.3/fpm/php.ini
expose_php = Off
display_errors = Off
log_errors = On
error_log = /var/log/php_errors.log
upload_max_filesize = 32M
post_max_size = 32M
max_execution_time = 60

Performance Tuning

1. Enable PHP OPcache

OPcache caches compiled PHP scripts in memory, eliminating the need to re-parse scripts on every request:

sudo nano /etc/php/8.3/fpm/conf.d/10-opcache.ini
opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2
opcache.fast_shutdown=1

2. Enable Nginx Gzip Compression

Add to the http block in /etc/nginx/nginx.conf:

gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
gzip_vary on;
gzip_min_length 1024;

3. Redis Object Cache (Optional)

For high-traffic WordPress sites, Redis dramatically reduces database queries:

sudo apt install redis-server php8.3-redis -y
sudo systemctl enable redis
sudo systemctl start redis

Need a reliable VPS to run your LEMP Stack?

View AsiaGB VPS Plans

Frequently Asked Questions

What is LEMP Stack?

LEMP Stack is a set of open-source software for hosting web applications: Linux (OS), Nginx (web server), MariaDB/MySQL (database), and PHP (server-side language). The name comes from the initials of each component.

What's the difference between LEMP and LAMP?

The only difference is the web server. LAMP uses Apache while LEMP uses Nginx. Nginx uses an event-driven architecture that handles concurrent connections more efficiently, using less RAM. It's particularly well-suited for high-traffic sites and VPS instances with limited memory.

Which PHP version should I use in 2026?

PHP 8.3 is recommended for production (security support until December 2027). PHP 8.4 is suitable for new projects needing the latest features. Avoid PHP 8.2 as it reaches security-only end of life in December 2026. Always check php.net for the current support table.

Is MariaDB fully compatible with MySQL?

Yes, MariaDB is a drop-in MySQL replacement with near 100% compatibility. WordPress, Laravel, and most web applications work with MariaDB without any code changes. MariaDB uses the same connection drivers (PDO_MySQL, mysqli) as MySQL.

Does WordPress work on LEMP?

Absolutely. WordPress works very well on LEMP. You need to configure Nginx with the correct try_files directive for WordPress pretty permalinks (since Nginx doesn't support .htaccess). The configuration is straightforward and well-documented.

What are the minimum VPS specs for LEMP Stack?

For small to medium websites: 1GB RAM, 1 CPU core, 20GB SSD. For production with real traffic: 2GB+ RAM, 2 CPU cores, 40GB+ SSD. LEMP is more memory-efficient than LAMP, so it performs well on budget VPS plans.