🇺🇸 Welcome from the USA! We have special plans for you.
View US Hosting Plans →

Install LEMP on VPS (Nginx, MySQL, PHP)

📅 15/06/2026 ⏱ 5 min de lectura
PlatiniumHost

Escrito por

Luis Contreras · CEO & Fundador · +24 años en hosting

Install LEMP on a VPS (Nginx, MySQL, PHP)

The LEMP stack (Linux, Nginx, MySQL, PHP) is one of the most popular and efficient server configurations for hosting dynamic web applications and high-traffic sites. While LAMP uses Apache, LEMP stands out for its use of Nginx (pronounced "engine-x"), a web server known for its superior performance, ability to handle a large number of concurrent connections, and efficiency in resource consumption. If you are looking to optimize your hosting infrastructure on a PlatiniumHost VPS, installing LEMP is an excellent starting point. This guide will walk you step-by-step through the complete installation of Nginx, MySQL (MariaDB), and PHP on your server.

This configuration is ideal for developers, businesses, and any user who needs a robust and scalable server for their web projects, from personal blogs to complex enterprise applications. Unlike solutions with control panels like cPanel, which simplify administration but add a layer of abstraction and resources, a manual LEMP installation gives you total control and direct optimization over each component.

Prerequisites

  • A VPS server with Ubuntu 20.04 or higher (although the commands are similar for other Debian-based distributions).
  • SSH access to the server with a user with sudo privileges or as root.
  • Basic knowledge of the Linux command line.

Step 1: Update the System

Before installing any new software, it's good practice to ensure all packages on your system are up to date. This ensures you are using the latest stable versions and have the most recent security fixes.

sudo apt update sudo apt upgrade -y

Step 2: Install Nginx

Nginx will be our web server, responsible for serving static files and forwarding PHP requests to PHP-FPM. Its asynchronous architecture makes it exceptionally fast and efficient.

sudo apt install nginx -y

Once installed, Nginx should start automatically. You can check its status and enable it to start with the system:

sudo systemctl start nginx sudo systemctl enable nginx sudo systemctl status nginx
Tip: If you have a firewall enabled (like UFW), make sure to allow HTTP and HTTPS traffic. You can do this with sudo ufw allow 'Nginx Full' or sudo ufw allow 80/tcp and sudo ufw allow 443/tcp.

To confirm that Nginx is working, open your web browser and navigate to your VPS's IP address. You should see the default Nginx welcome page.

Step 3: Install MySQL (MariaDB)

MySQL is the most widely used database in the web environment. In many Linux distributions, MariaDB, a community fork of MySQL, is used as a replacement. It is fully compatible and offers performance improvements.

sudo apt install mariadb-server mariadb-client -y

After installation, it is crucial to run the security script to protect your database server.

sudo mysql_secure_installation
Important: Follow the script's prompts. You will be asked to set a root password, remove anonymous users, disable remote root login, and remove the test database. Answer 'Y' to most questions for a secure setup.

You can check the status of the MariaDB service with:

sudo systemctl status mariadb

Step 4: Install PHP and PHP-FPM

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation that offers additional features for high-traffic sites, making it perfect for working with Nginx.

sudo apt install php-fpm php-mysql php-cli php-curl php-json php-gd php-mbstring php-xml php-zip -y

This command installs PHP-FPM and some common extensions that most PHP applications require. You can add more extensions according to your project's needs.

Check the status of PHP-FPM:

sudo systemctl status php7.4-fpm # or php8.x-fpm depending on your PHP version

Step 5: Configure Nginx for PHP-FPM

Now we need to tell Nginx how to process PHP files. We will edit the default server block or create a new one for your site. For this example, we will modify the default Nginx configuration file.

sudo nano /etc/nginx/sites-available/default

Find the server section and make the following modifications. Uncomment the lines related to PHP and ensure the configuration is similar to this:

server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php index.html index.htm index.nginx-debian.html; server_name your_domain_or_ip; # Replace with your domain or IP location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Make sure the PHP version matches } location ~ /\.ht { deny all; } }
Tip: The line fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; must point to the correct socket for your PHP-FPM version. If you installed PHP 8.x, it would be php8.x-fpm.sock.

Save and close the file (Ctrl+X, Y, Enter). Then, test the Nginx configuration and restart it:

sudo nginx -t sudo systemctl restart nginx

Step 6: Create a PHP Test File

To verify that PHP-FPM is working correctly with Nginx, we will create a simple info.php file in your website's root directory.

sudo nano /var/www/html/info.php

Add the following content to the file:

<?php phpinfo(); ?>

Save and close the file. Now, open your web browser and navigate to http://your_domain_or_ip/info.php. You should see the PHP information page, which confirms that LEMP has been installed and configured correctly. Once you have verified this, it is advisable to delete the info.php file for security reasons.

sudo rm /var/www/html/info.php

Conclusion

Congratulations! You have successfully installed the LEMP stack (Nginx, MySQL, PHP) on your VPS. You now have a solid, high-performance foundation for hosting your web applications. This environment offers you total control and great flexibility, ideal for projects that demand maximum performance and customization.

From here, you can configure your domains, install SSL certificates (e.g., with Let's Encrypt), deploy your web applications or CMS like WordPress, and continue optimizing your server. Remember that PlatiniumHost offers you the necessary VPS resources for your projects to thrive with this powerful configuration. If you prefer a simpler solution with a graphical interface, you can always opt for a VPS with cPanel pre-installed, but for maximum performance and customization, LEMP is the expert choice.

💬 ¿En qué podemos ayudarte?

Selecciona un agente de soporte

¿Hablamos?