Lightweight NGINX + MariaDB + PHP-FPM Setup (Debian/Ubuntu)
Step 1: Update your system
sudo apt update && sudo apt upgrade -y
Step 2: Install NGINX
sudo apt install nginx -y
- Start and enable NGINX:
sudo systemctl enbale --now nginx
Step 3: Install MariaDB
sudo apt install mariadb-server mariadb-client -y
- Secure MariaDB (set root password, remove test DBs, etc):
sudo mysql_secure_installation
Step 4: Install PHP and PHP-FPM with necessary modules
sudo apt install php-fpm php-mysql php-cli php-curl php-zip php-mbstring php-xml php-gd -y
- Start and enable PHP-FPM:
sudo systemctl enable --now php-8.2-fpm
Step 5: Configure NGINX to use PHP-FPM
create /etc/nginx/sites directory sudo mkdir -p /etc/nginx/sites
Create or edit your site config, e.g., /etc/nginx/sites
/example.com
server {
listen 80;
listen [::]:80;}
server_name example.com www.example.com;
root /www/example.com;
index index.html index.php;
location / {
try_files $uri $uri/ inedex.php$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
add include /etc/nginx/sites/*; in /etc/nginx/nginx.conf http block then reload nginx if you see successful after executing sudo nginx -t
sudo nginx -tsudo systemctl reload nginx
Step 6: Create your web root directory and set permissions
sudo mkdir -p /www/examppe.com
sudo chown -R www-data:www-data /www/example.com
sudo chmod -R 755 /www/example.com
Step 7: Test PHP
Create a test PHP file:
echo "<?php phpinfo(); ?>" | sudo tee /www/example.com/info.php
Visit: http://example.com/info.php
in your browser to verify PHP works.
Step 8: Firewall (optional but recommended)
Allow HTTP and HTTPS:
sudo apt install ufw && sudo ufw allow 22 && sudo systemctl enable --now ufw
sudo ufw allow 80,443/tcp && sudo ufw reload
Optional Step 9: Install Certbot for SSL (Let’s Encrypt)
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
Summary
- NGINX: Web server
- MariaDB: Database server
- PHP-FPM: PHP processor for NGINX
This setup is lightweight, secure, and fast without any control panel overhead.