How to install nginx, PHP and MariaDB on a cloud server, connect your website and add a free certificate.
If your website has outgrown shared hosting or needs custom settings, you can host it on a cloud server. Below is the most common set-up: the nginx web server, PHP and the MariaDB database (which is compatible with MySQL). Replace example.co.uk with your own domain.
Ubuntu and Debian
sudo apt update
sudo apt install nginx php-fpm php-mysql mariadb-serverPut your website files in /var/www/example.co.uk. If the website writes files itself — uploads, cache — give those folders to the user that PHP runs as: sudo chown -R www-data:www-data /var/www/example.co.uk/uploads. For more about permissions, see File permissions: chmod and chown.
Create the file /etc/nginx/sites-available/example.co.uk:
server {
listen 80;
server_name example.co.uk www.example.co.uk;
root /var/www/example.co.uk;
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.4-fpm.sock;
}
}In fastcgi_pass use your own PHP version: on Debian 13 it is 8.4, on Ubuntu 26.04 it is 8.5. The exact name is shown by ls /run/php/. Enable the site:
sudo ln -s /etc/nginx/sites-available/example.co.uk /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginxAlmaLinux
sudo dnf install nginx php-fpm php-mysqlnd mariadb-server
sudo systemctl enable --now nginx php-fpm mariadbAlmaLinux 9 installs PHP 8.0 by default. If you need a newer version, select it before installing: sudo dnf module enable php:8.3. AlmaLinux 10 comes with PHP 8.3 straight away.
Describe your site in /etc/nginx/conf.d/example.co.uk.conf — as in the example above, but instead of the two PHP lines write one: include /etc/nginx/default.d/php.conf;. The php-fpm package has already put ready-made PHP settings there.
SELinux only lets the web server access files with the right label. If you moved the website files from a home folder with mv, refresh the labels: sudo restorecon -Rv /var/www — there is more in the AlmaLinux cheat sheet.
A database for your website
Log in to the database as the administrator — no password is needed, sudo is enough: sudo mariadb. Create a database and a user:
CREATE DATABASE site CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'site'@'localhost' IDENTIFIED BY 'a-strong-password';
GRANT ALL PRIVILEGES ON site.* TO 'site'@'localhost';Enter this database name, user name and password in your website’s settings; the database host is localhost.
Domain and a free certificate
Point your domain at the server with an A record containing the server’s IP address, which you add in the DNS settings of your domain. Once the domain opens your site over http, issue a Let’s Encrypt certificate.
Ubuntu and Debian:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.co.uk -d www.example.co.ukAlmaLinux:
sudo dnf install epel-release
sudo dnf install certbot python3-certbot-nginx
sudo certbot --nginx -d example.co.uk -d www.example.co.uk
sudo systemctl enable --now certbot-renew.timercertbot adds the HTTPS settings to nginx for you, and the certificate renews automatically. If a firewall is enabled, open ports 80 and 443 in it. If the website does not open, see Web server will not start: nginx or Apache.
To check renewal, add a domain, issue a wildcard certificate or fix errors, see Let’s Encrypt certificate: certbot.
Didn’t find the answer? Ask our support team — we’ll help.