Table of Contents
What you will read?
LEMP stack is a popular set of open-source software used to host dynamic websites and applications. It includes Linux, Nginx (pronounced “Engine-X”), MariaDB/MySQL, and PHP.
Step 1 – Update System
Before doing anything, update your packages:
sudo apt update && sudo apt upgrade -y
Step 2 – Install Nginx (Web Server)
Nginx is a high-performance web server that will serve your website content:
sudo apt update && sudo apt upgrade -y
Start and enable Nginx:
sudo systemctl enable --now nginx
Check if it’s running:
systemctl status nginx
Step 3 – Install MariaDB (or MySQL)
MariaDB is a reliable open-source alternative to MySQL. It’s used for storing databases:
sudo apt install mariadb-server mariadb-client -y
Secure your installation:
sudo mysql_secure_installation
During setup, you can:
-
Set a root password
-
Remove anonymous users
-
Disallow remote root login
-
Remove test databases
Step 4 – Install PHP and Extensions
PHP processes server-side scripts. To integrate PHP with Nginx, install php-fpm and essential modules:
sudo apt install php-fpm php-mysql -y
Verify PHP version:
php -v
Step 5 – Configure Nginx to Use PHP
Create a sample server block (virtual host):
sudo nano /etc/nginx/sites-available/example.com
Paste the following configuration (replace example.com and paths as needed):
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the new site and reload Nginx:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Step 6 – Test PHP Processing
Create a test file:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Open your browser and visit:http://your-server-ip/info.php
You should see the PHP info page.
You’ve successfully installed the LEMP stack on Debian 12. This setup is now ready for hosting PHP-based applications like WordPress, Laravel, and more.
Need help with advanced configuration or hosting? Contact our support team at DropVPS.com.
