Setting Up a LEMP Stack
Install Linux, Nginx, MySQL, and PHP on your GoZen Host VPS. The foundation for modern web applications.
4 min read
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 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)
Open your server’s IP in a browser. You should see the Nginx welcome page.
Install MariaDB
MariaDB is a drop-in MySQL replacement and the default MySQL-compatible server on Debian, Ubuntu, and Rocky/AlmaLinux.
Secure the Installation
sudo mysql_secure_installation
Answer the prompts:
| Prompt | Answer |
|---|---|
| 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
This guide installs PHP 8.4.
Start PHP-FPM:
sudo systemctl enable --now php8.4-fpm # Ubuntu/Debian
sudo systemctl enable --now php-fpm # Rocky/Alma
Configure Nginx for PHP
Only add immutable to the Cache-Control header if your asset filenames change on every release (for example style.3f9a1c.css). Otherwise browsers keep serving old CSS and JS after you update the site.
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 # Ubuntu/Debian
sudo chown -R nginx:nginx /var/www/mysite # Rocky/Alma
Visit http://yourdomain.com (or your server IP). You should see the PHP info page.
Delete index.php after testing. It exposes your full server configuration. Replace it with your actual application.
Add SSL with Let’s Encrypt
sudo apt install certbot python3-certbot-nginx -y # Ubuntu/Debian
sudo dnf install certbot python3-certbot-nginx -y # Rocky/Alma (from EPEL)
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
| Component | Version | Config Location |
|---|---|---|
| Nginx | Latest from package manager | /etc/nginx/ |
| MariaDB | Your distro’s packaged version | /etc/mysql/ (Ubuntu/Debian), /etc/my.cnf.d/ (Rocky/Alma) |
| PHP-FPM | 8.4 | /etc/php/8.4/fpm/ (Ubuntu/Debian), /etc/php-fpm.d/ (Rocky/Alma) |
| Certbot | Latest | Auto-managed in /etc/letsencrypt/ |
What to Do Next
- Installing WordPress: deploy WordPress on your LEMP stack
- Server Hardening Basics: secure the server before going live
- Monitoring Your Server: watch for resource issues
Last updated 21 Oct 2026, 00:00 +0300.