How to install WordPress on LEMP stack (Nginx) on a VPS

WordPress is one of the most popular content management systems (CMS) in the world, powering millions of websites across the globe. For those looking to leverage the performance benefits of a LEMP stack (Linux, Nginx, MariaDB/MySQL, PHP) on a Virtual Private Server (VPS), installing WordPress can optimize your web presence with robust and scalable solutions. This article will guide you through the steps of installing WordPress on a LEMP stack and configuring Nginx for optimal performance.

Step-by-Step Guide to Installing WordPress

  1. Update Your Server and Install LEMP Stack: Before installing WordPress, ensure that your VPS is up-to-date. Connect to your server via SSH and run sudo apt update && sudo apt upgrade. Next, install the LEMP stack. You can install Nginx, MySQL, and PHP with the command: sudo apt install nginx mysql-server php-fpm php-mysql. During the installation, you will be prompted to set a password for the MySQL root user.

  2. Create a MySQL Database and User: WordPress uses a database to manage data. Log in to the MySQL shell with sudo mysql and create a new database and user for WordPress. For example, use:

    CREATE DATABASE wordpress;
    CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
    GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;

    Replace ‘password’ with a secure password of your choice.

  3. Download and Configure WordPress: Go to the web root directory (typically /var/www/html) and remove any existing files. Download the latest WordPress version with wget https://wordpress.org/latest.tar.gz. Extract the archive with tar xzvf latest.tar.gz and move the contents to the root directory. Configure WordPress by copying the sample configuration file: cp wp-config-sample.php wp-config.php. Edit the wp-config.php file to enter the details of the database name, user, and password you created earlier.

Configuring Nginx for WordPress on LEMP

  1. Configure Nginx Server Block: Start by creating a new server block configuration for your WordPress site. Open a new configuration file in Nginx’s sites-available directory with sudo nano /etc/nginx/sites-available/wordpress. Configure the server block to listen on the default web port and to serve files from your WordPress directory. The configuration should include the handling of PHP files using the PHP processor and specify the server name (domain or IP).

  2. Enable Permalinks in WordPress: To use SEO-friendly URL structures, WordPress needs to rewrite rules that must be specified in Nginx’s configuration. Inside your server block, add the following location block:

    location / {
       try_files $uri $uri/ /index.php?$args;
    }

    This directive tells Nginx to serve any PHP scripts directly and to pass all other requests to index.php with the original query string parameters.

  3. Activate the Configuration and Restart Nginx: After configuring your server block, enable it by creating a symbolic link to the sites-enabled directory with sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/. Test the Nginx configuration for errors with sudo nginx -t. If everything is set correctly, restart Nginx to apply the changes with sudo systemctl restart nginx.

By following the outlined steps, you can successfully install WordPress on a LEMP stack using Nginx on your VPS. This setup not only leverages the speed and efficiency of Nginx but also ensures that your WordPress site is scalable and secure. Remember to regularly maintain and update your WordPress installation and Nginx server to protect against vulnerabilities and ensure optimal performance.

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