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

When setting up a powerful web server, the LEMP stack — which stands for Linux, Nginx (pronounced "Engine-X"), MySQL, and PHP — is a popular choice among developers. This stack is known for its stability, efficiency, and simplicity in hosting dynamic websites or applications. In this guide, we’ll walk through the steps of installing a LEMP stack on a Virtual Private Server (VPS). This setup is ideal for those looking to deploy scalable and performant web applications.

Step 1: Setting Up Nginx on Your VPS

To begin, you must install Nginx, a high-performance web server software that is more resource-friendly than its counterparts. Firstly, update your VPS package index by running sudo apt update on Debian-based systems. After updating, install Nginx using sudo apt install nginx. Once the installation is complete, you can start the Nginx service with sudo systemctl start nginx, and enable it to run on boot using sudo systemctl enable nginx.

After Nginx is installed and running, it’s essential to check its status to confirm it’s operating correctly. You can check this by executing sudo systemctl status nginx. If everything is set up correctly, the output should indicate that Nginx is active and running. Additionally, you can verify that Nginx is serving pages by navigating to your VPS’s IP address in a web browser, which should display the default Nginx landing page.

Configuring Nginx involves editing its configuration files, typically found in /etc/nginx/nginx.conf and the sites-available directory. For a basic setup, you might need to adjust server blocks to direct requests to your website files and set up locations for handling different requests. Remember, after making changes to configuration files, you must reload Nginx to apply them, which can be done using sudo systemctl reload nginx.

Step 2: Installing MySQL Server

MySQL is a robust database management system essential for managing the data of most modern web applications. To install MySQL, use the command sudo apt install mysql-server on your Debian-based VPS. During the installation process, you may be prompted to create a root password, which is crucial for securing your database.

Once the installation is complete, it’s advisable to run a security script that comes pre-installed with MySQL. This script can be started with sudo mysql_secure_installation. Following the prompts will allow you to set a strong root password if you haven’t already, remove anonymous users, disallow root login remotely, and remove test databases. These security enhancements are recommended to protect your new server.

After securing your installation, log into the MySQL console by typing sudo mysql -u root -p, and enter the root password you set earlier. This step confirms that MySQL is correctly installed and operational. From here, you can create databases, assign user permissions, and perform other necessary database management tasks to support your applications.

By following these steps, you have installed and configured two major components of the LEMP stack: Nginx as your web server and MySQL as your database server. Each component plays a crucial role in web application hosting, with Nginx serving web pages and handling client requests, and MySQL storing and retrieving data as needed. With these components in place, the next step is to install PHP, which will complete the LEMP stack, enabling you to deploy dynamic web applications on your VPS.

Hot this week

How to Start Small-Scale eCommerce in Zimbabwe (Step-by-Step Guide)

eCommerce is booming across Africa, and Zimbabwe is no...

How to Create and Monetize Content (YouTube, Blog, TikTok) from Zimbabwe

In 2025, creating content is one of the most...

How to Get Cheap or Refurbished Tech Gear (Phones & Laptops) in Zimbabwe That Still Works Well

Buying a new phone or laptop in Zimbabwe can...

How to Earn an Income Online in Zimbabwe Without Special Skills (2025 Guide)

For many Zimbabweans, earning a living has become harder...

How to Access Cheaper Internet Data in Zimbabwe Without Losing Speed or Reliability (2025 Guide)

Tired of burning through data bundles before month-end? You’re...

Topics

How to Start Small-Scale eCommerce in Zimbabwe (Step-by-Step Guide)

eCommerce is booming across Africa, and Zimbabwe is no...

How to Create and Monetize Content (YouTube, Blog, TikTok) from Zimbabwe

In 2025, creating content is one of the most...

How to Earn an Income Online in Zimbabwe Without Special Skills (2025 Guide)

For many Zimbabweans, earning a living has become harder...

How to Access Cheaper Internet Data in Zimbabwe Without Losing Speed or Reliability (2025 Guide)

Tired of burning through data bundles before month-end? You’re...

From $200 to $199: How Tremhost Beats Cloudflare’s Own Pricing Model

Cloudflare’s Business Plan is legendary. It includes enterprise-grade features...

Cheaper Than Cloudflare Itself? How Tremhost Bundles World-Class Security for Less

When it comes to website performance and protection, Cloudflare...
spot_img

Related Articles

Popular Categories

spot_imgspot_img