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 pricingRelated tutorials
Web servers
How to install phpMyAdmin to manage MySQL from the browser
Manage your MySQL databases from a web interface with phpMyAdmin, installed and secured correctly.
Updated 7/20/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 7/20/2026Web serversHow to host a static site or a React/Vue app
Publish a static site or a React/Vue build on Nginx, with correct routing for single-page apps.
Updated 7/20/2026