CloudLinux.ro
Web servers

How to install a LEMP stack (Nginx, PHP, MySQL)

Updated 7/20/2026

A LEMP stack (Linux, Nginx, MySQL, PHP) is the foundation for most PHP sites, including WordPress. Here is how to install it.

1. Nginx

apt-get update -y
apt-get install -y nginx

2. MySQL

apt-get install -y mysql-server
mysql_secure_installation

3. PHP-FPM

apt-get install -y php-fpm php-mysql

4. Wire Nginx to PHP

In the server block, add PHP file processing:

server {
    listen 80;
    server_name example.com;
    root /var/www/mysite;
    index index.php index.html;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}
nginx -t && systemctl reload nginx

5. Test PHP

echo "<?php phpinfo();" > /var/www/mysite/info.php

Open /info.php in a browser, then delete the file. For the database, see MySQL users and privileges.

Put this guide into practice on your own VPS

EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.

See pricing

Related tutorials