How to install a LEMP stack (Nginx, PHP, MySQL)
Updated 10/16/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 deploy a Laravel app to production
Deploy Laravel properly on a VPS: Nginx, PHP-FPM, permissions, optimizations and the queue worker.
Updated 10/16/2026Web serversHow 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/16/2026Web serversHow to force HTTPS and redirect HTTP
After installing SSL, make sure every visitor uses HTTPS, with a permanent 301 redirect from HTTP.
Updated 10/16/2026