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

Top 5 Beaded Jewelry Trends in Africa (2025)

Beaded jewelry continues to thrive in Africa, blending traditional...

Crocheting for Beginners: Step-by-Step African Patterns

Crocheting is a rewarding craft that allows you to...

DIY African Black Soap: Homemade Recipes & Benefits

African black soap is renowned for its natural ingredients...

Where to Buy Candle-Making Supplies in Nigeria

If you're interested in starting candle-making in Nigeria, here...

How to Make Tie-Dye at Home (African Fabric Edition)

Creating tie-dye patterns on African fabrics is a fun...

Topics

Top 5 Beaded Jewelry Trends in Africa (2025)

Beaded jewelry continues to thrive in Africa, blending traditional...

Crocheting for Beginners: Step-by-Step African Patterns

Crocheting is a rewarding craft that allows you to...

DIY African Black Soap: Homemade Recipes & Benefits

African black soap is renowned for its natural ingredients...

Where to Buy Candle-Making Supplies in Nigeria

If you're interested in starting candle-making in Nigeria, here...

How to Make Tie-Dye at Home (African Fabric Edition)

Creating tie-dye patterns on African fabrics is a fun...

5 Best Sewing Machines for Beginners in Africa

Starting your sewing journey can be exciting, and choosing...

DIY Wall Décor Ideas Using African Prints

Transform your space with vibrant African prints! Here are...

How to Start a Bead-Making Business in Africa: Profitable Skills

Starting a bead-making business can be a rewarding venture...
spot_img

Related Articles

Popular Categories

spot_imgspot_img