Linux VPS

Install Nginx, PHP and MariaDB (LEMP)

Set up a web server stack for PHP websites on Ubuntu 24.04. · 8 min read

1. Install packages

apt update
apt -y install nginx mariadb-server php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip

2. Secure MariaDB

mysql_secure_installation

3. Create a database

mysql -u root -p
CREATE DATABASE site;
CREATE USER 'site'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL ON site.* TO 'site'@'localhost';
FLUSH PRIVILEGES;

4. Configure a site

nano /etc/nginx/sites-available/example.com
server {
  listen 80;
  server_name example.com www.example.com;
  root /var/www/example.com;
  index index.php index.html;
  location / { try_files $uri $uri/ /index.php?$args; }
  location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.3-fpm.sock; }
}
mkdir -p /var/www/example.com
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

5. Add HTTPS

Follow Free SSL with Certbot.

Order a server built by real engineers or talk to our team — we are online 24/7. Support →

Linux VPS

All tutorials

Ready to launch your project?

Order a server built by real engineers or talk to our team — we are online 24/7.