How to install WordPress on a VPS

How to Install WordPress on a VPS

Installing WordPress on a Virtual Private Server (VPS) gives you greater control, customization, and scalability compared to shared hosting. This guide will walk you through the process, whether you’re using a Linux-based VPS with a LAMP stack (Linux, Apache, MySQL, PHP) or a similar environment.


1. Set Up Your Server Environment

a. Update Your System

Log in to your VPS via SSH and update your package lists:

sudo apt update && sudo apt upgrade -y

b. Install Apache, MySQL, and PHP (LAMP Stack)

For Ubuntu or Debian-based systems, run:

sudo apt install apache2 mysql-server php php-mysql libapache2-mod-php php-cli php-curl php-gd php-mbstring php-xml php-xmlrpc -y

Tip: If you prefer Nginx, install and configure it accordingly.

c. Secure MySQL

Run the security script to set a root password and remove insecure defaults:

sudo mysql_secure_installation

2. Create a Database for WordPress

a. Log into MySQL

sudo mysql -u root -p

b. Create the Database and User

Inside the MySQL shell, run:

CREATE DATABASE wordpress_db DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace your_strong_password with a secure password.


3. Download and Configure WordPress

a. Download WordPress

Navigate to the web root directory (commonly /var/www/html) and download WordPress:

cd /var/www/html
sudo wget https://wordpress.org/latest.tar.gz
sudo tar -xzf latest.tar.gz
sudo rm latest.tar.gz

This extracts WordPress into a folder called wordpress.

b. Configure Permissions

Set the correct ownership and permissions:

sudo chown -R www-data:www-data /var/www/html/wordpress
sudo find /var/www/html/wordpress -type d -exec chmod 755 {} \;
sudo find /var/www/html/wordpress -type f -exec chmod 644 {} \;

c. Create the WordPress Configuration File

Copy the sample configuration file:

cd wordpress
sudo cp wp-config-sample.php wp-config.php

Edit wp-config.php:

sudo nano wp-config.php

Replace the following lines with your database details:

define( 'DB_NAME', 'wordpress_db' );
define( 'DB_USER', 'wp_user' );
define( 'DB_PASSWORD', 'your_strong_password' );
define( 'DB_HOST', 'localhost' );

Save and exit (Ctrl+O, Enter, Ctrl+X).


4. Configure Apache (or Nginx) for WordPress

For Apache Users:

a. Create a Virtual Host File

Create a new Apache configuration file:

sudo nano /etc/apache2/sites-available/wordpress.conf

Insert the following configuration (adjust paths and domain as needed):

<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName yourdomain.com
    DocumentRoot /var/www/html/wordpress

    <Directory /var/www/html/wordpress>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/wordpress_error.log
    CustomLog ${APACHE_LOG_DIR}/wordpress_access.log combined
</VirtualHost>

Save and exit.

b. Enable the Site and Rewrite Module

sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2

For Nginx Users:

a. Create a Server Block File

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

Insert the following configuration:

server {
    listen 80;
    server_name yourdomain.com;
    root /var/www/html/wordpress;
    
    index index.php index.html index.htm;

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

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; # Adjust PHP version if needed
    }

    location ~ /\.ht {
        deny all;
    }
}

Save and exit.

b. Enable the Server Block and Restart Nginx

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo systemctl restart nginx

5. Complete the WordPress Installation

  • Open Your Browser:
    Visit your domain (e.g., http://yourdomain.com).
  • Follow the On-Screen Instructions:
    Select your language, set up your site title, admin username, password, and email address. Complete the installation by clicking “Install WordPress.”
  • Log In:
    Once installed, log into your WordPress dashboard at http://yourdomain.com/wp-admin.

Final Thoughts

Installing WordPress on a VPS gives you the flexibility and power to manage your website on your own terms. By following these steps, you’ll have a robust, self-hosted WordPress installation ready for customization and growth.

Need further assistance? Many hosting communities and forums can offer additional tips and troubleshooting advice to help you optimize your setup. Enjoy your new WordPress site 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