This guide is for GoZen VPS and Cloud servers.

LEMP is Linux + Nginx + MySQL/MariaDB + PHP. It’s the modern alternative to LAMP (which uses Apache). Nginx handles static files faster and uses less memory. It’s the better choice for most workloads.

This guide assumes you’ve completed initial server setup: non-root user, SSH keys, and a firewall.

Install Nginx

Open your server’s IP in a browser. You should see the Nginx welcome page.

Open HTTP and HTTPS in the firewall:

  sudo ufw allow 'Nginx Full'     # UFW (Ubuntu/Debian)
# or
sudo firewall-cmd --permanent --add-service={http,https} && sudo firewall-cmd --reload   # firewalld (Rocky/Alma)
  

Install MariaDB

MariaDB is a drop-in MySQL replacement. It’s faster, fully open source, and more actively maintained.

Secure the Installation

  sudo mysql_secure_installation
  

Answer the prompts:

PromptAnswer
Set root password?Y (set a strong password)
Remove anonymous users?Y
Disallow root login remotely?Y
Remove test database?Y
Reload privilege tables?Y

Create a Database and User

  sudo mysql
  
  CREATE DATABASE myapp;
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'your-strong-password';
GRANT ALL PRIVILEGES ON myapp.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
  

Install PHP

Start PHP-FPM:

  sudo systemctl enable php8.3-fpm    # or php-fpm on Rocky/Alma
sudo systemctl start php8.3-fpm
  

Configure Nginx for PHP

Create a site configuration:

  sudo nano /etc/nginx/sites-available/mysite
  
  server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/mysite;
    index index.php index.html;

    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;
    }

    location ~ /\.ht {
        deny all;
    }

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

Enable the site:

  sudo ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default    # Remove default site
sudo nginx -t
sudo systemctl reload nginx
  

Verify the Stack

Create a test file:

  sudo mkdir -p /var/www/mysite
echo '<?php phpinfo(); ?>' | sudo tee /var/www/mysite/index.php
sudo chown -R www-data:www-data /var/www/mysite
  

Visit http://yourdomain.com (or your server IP). You should see the PHP info page.

Add SSL with Let’s Encrypt

  sudo apt install certbot python3-certbot-nginx -y    # Ubuntu/Debian
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
  

Certbot auto-configures Nginx for HTTPS and sets up auto-renewal.

Test the renewal:

  sudo certbot renew --dry-run
  

Stack Summary

ComponentVersionConfig Location
NginxLatest from package manager/etc/nginx/
MariaDB10.x/etc/mysql/
PHP-FPM8.3/etc/php/8.3/fpm/
CertbotLatestAuto-managed in /etc/letsencrypt/

What to Do Next

Last updated 05 Apr 2026, 00:00 +0200. history

Was this page helpful?