How to install a LEMP stack (Nginx, PHP, MySQL)
Updated 10/23/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 pricingRelated tutorials
Web servers
How to optimize Nginx performance: gzip, cache and HTTP/2
Make your site faster with gzip compression, static file caching and HTTP/2, a few lines of config.
Updated 10/23/2026Web serversHow to deploy a Node.js app to production
Run a Node.js app reliably in production with PM2 and Nginx, with auto-restart and HTTPS.
Updated 10/23/2026Web serversHow to host multiple sites on one server
Use Nginx server blocks to run multiple domains on the same VPS, each with its own site.
Updated 10/23/2026