sudo apt install nginx mariadb-server php-fpm php-mysql, secure the database with sudo mysql_secure_installation, then add a server block that passes .php files to unix:/run/php/php8.3-fpm.sock. Test with sudo nginx -t, reload Nginx and open a PHP test page. On Debian 13 the socket is php8.4-fpm.sock.
Before you start
- LEMP means Linux, Engine-x (Nginx), MariaDB or MySQL, and PHP. It runs most PHP apps, such as WordPress.
- Use a user with
sudo. If you areroot, leave outsudo. - Allow ports 80 and 443 in your firewall, as in install Nginx.
- PHP version by release: Ubuntu 22.04 has 8.1, Ubuntu 24.04 has 8.3, Debian 12 has 8.2, Debian 13 has 8.4, AlmaLinux / Rocky 10 has 8.3. Need another version? See multiple PHP versions.
How to install Nginx, MariaDB and PHP
- Ubuntu / Debian
- AlmaLinux / Rocky 10
- AlmaLinux / Rocky 9
How to secure MariaDB
How to connect Nginx to PHP-FPM
PHP-FPM (FastCGI Process Manager) runs PHP as its own service. Nginx hands it every.php request through a socket file.
1
Create the site folder
2
Create the server block
- Ubuntu / Debian
- AlmaLinux / Rocky
Create Change
/etc/nginx/sites-available/example.com:php8.3 to match php -v (for example php8.4 on Debian 13). Then enable it:3
Test and reload Nginx
How to check it worked
Create a small test file:fpm-fcgi proves Nginx passed the request to PHP-FPM. The patch number may be newer on your server. Delete the file afterwards:
Frequently asked questions
I get “502 Bad Gateway”. What is wrong?
Nginx cannot reach PHP-FPM. Usually the socket name infastcgi_pass does not match the installed PHP version, or php-fpm is not running. See fix 502 Bad Gateway.
My browser downloads the .php file instead of running it. Why?
Thelocation ~ \.php$ block is missing or the site you edited is not enabled. Run sudo nginx -T | grep -n fastcgi_pass to see what Nginx actually loaded.
Should I use MariaDB or MySQL?
Both work for WordPress and most PHP apps. Ubuntu and Debian ship MariaDB asmariadb-server. See install MySQL or MariaDB.
How do I add HTTPS?
Run Certbot once your domain points to the server. See free SSL with Certbot.Related guides
VPS and dedicated server guides
Every server guide in one place.
Install WordPress
Put WordPress on your LEMP stack.
Create a database and user
One database per app.
Increase PHP upload size
Raise upload and memory limits.
Install a LAMP stack
The same with Apache.
Checked against the official Ubuntu Server PHP documentation, Red Hat Enterprise Linux 9 PHP guide and Debian 13 release notes on 4 November 2026; Ubuntu commands tested on Ubuntu 24.04 LTS (Nginx 1.24.0, MariaDB 10.11, PHP 8.3.6). Commands can differ on other distributions or releases.
Need Extra Help?
If you encounter any issues, our support team is ready to assist:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026