
LEMP = Linux + Nginx + MariaDB + PHP
Perfect for hosting WordPress, Laravel, Piwigo or any PHP website.
πͺ Step 1: Connect to your Droplet
After creating your Droplet on DigitalOcean, connect to it using SSH:
ssh root@your_droplet_ipIf it asks for confirmation, type yes.
Now youβre inside your Ubuntu Server! π»
π Step 2: Update your system
Always start with updates to get the latest security fixes:
sudo apt update && sudo apt upgrade -yπ Step 3: Install Nginx (Web Server)
Nginx serves your website to visitors
sudo apt install nginx -y
sudo systemctl enable --now nginxCheck itβs working:
π Open your browser and visit http://your_droplet_public_ip . you should see the βWelcome to Nginx!β page.
ποΈ Step 4: Install MariaDB (Database Server)
MariaDB stores your websiteβs data.
sudo apt install mariadb-server
sudo systemctl enable --now mariadb
sudo systemctl start mariadb
sudo systemctl status mariadbSecure your Database Server here MariaDB (this step is interactive):
sudo mariadb_secure_installationSuggested answers:
Set root password: Y
Remove anonymous users: Y
Disallow root login remotely: Y
Remove test database: Y
Reload privilege tables: Y
β Done! MariaDB is now safe and running.
β After Running It
You can test that it’s working:
sudo mysql -u root -pπ§ Step 5: Install PHP (to process dynamic pages)
PHP makes your website interactive.
sudo apt install php-fpm php-mysql -yCheck PHP version:
php -vποΈ Step 6: Create your website folder
Weβll make a test site folder called demo.com (replace with your own domain).
π /var/www/demo.com/html
This is the recommended structure for production:
/var/www/
βββ demo.com/
β βββ html/
β βββ logs/
β βββ backups
sudo mkdir -p /var/www/demo.com
sudo chown -R www-data:www-data /var/www/demo.com
chmod -R 755 /var/www/demo.comβ
Cleaner & professional – Each site gets its own folder
β
Matches how Nginx is structured in /etc/nginx/sites-available/
β
Easier to manage multiple websites
β
Easier permissions and backups
β
Avoids mixing files with the default /var/www/html
Open Vim or Nano Editor
sudo vim /etc/nginx/sites-available/demo.comPaste this code to demo.com
server {
listen 80;
server_name demo.com www.demo.com;
root /var/www/demo.com;
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.3-fpm.sock;
}
location ~ /\\.ht {
deny all;
}
}Enable the site and test Nginx:
ln -s /etc/nginx/sites-available/demo.com /etc/nginx/sites-enabled/
nginx -t
systemctl reload nginxAdd a PHP test page:
echo "<?php phpinfo(); ?>" > /var/www/demo.com/index.phpThen visit: π http://your_droplet_public_ip
You should see a PHP info page β success! π
π Step 7 β Setup SSL with Letβs Encrypt
Install and set up Certbot
apt install certbot python3-certbot-nginx -y
certbot --nginx -d demo.com -d www.demo.com
systemctl enable certbot.timerTo test auto-renew:
certbot renew --dry-runπ§± Step 8 β Firewall Setup & PHP Extensions
π₯ Enable Firewall for Security
UFW (Uncomplicated Firewall) protects your server from unwanted access.
Run:
ufw allow OpenSSH
ufw allow 'Nginx Full'
ufw enable
ufw statusβ This keeps SSH, HTTP, and HTTPS open β blocking everything else.
π§© Install Useful PHP Extensions
Now, install all recommended PHP extensions for web apps:
sudo apt install php8.3-mysql php8.3-curl php8.3-zip php8.3-xml php8.3-mbstring php8.3-gd php8.3-intl php8.3-imagick -yEach one has a purpose:
Extension Purpose
php8.3-mysql Connect PHP to MariaDB
php8.3-curl Communicate with APIs
php8.3-zip Handle ZIP files (plugins/themes)
php8.3-xml Parse XML, RSS, and feeds
php8.3-mbstring Handle Unicode and multibyte text
php8.3-gd Create and resize images
php8.3-intl Support multiple languages
php8.3-imagick Advanced image editing and compression
Restart PHP-FPM to apply changes
sudo systemctl restart php8.3-fpmConfirm Imagick is working:
php -m | grep imagickIt should output:
imagick
β Youβre Done!
Congratulations π π Your LEMP Stack is ready fully optimized and secure.
You now have:
Nginx (Web Server)
MariaDB (Database)
PHP 8.3 + Extensions + Imagick
UFW Firewall + Deployment of SSL Certificates