How to Install WordPress on a VPS

If you want to create a blog or website, WordPress is one of the most popular content management systems (CMS) available. In this tutorial, we will show you how to install WordPress on a Virtual Private Server (VPS) using Apache and MySQL.

Step 1: Install Required Packages

Connect to your VPS using SSH and run the following commands:

sudo apt-get update
sudo apt-get install apache2 mysql-server php libapache2-mod-php php-mysql php-curl php-gd php-xml php-mbstring

Step 2: Configure MySQL

Run the following command to secure your MySQL installation:

sudo mysql_secure_installation

Answer the questions to set the root password, remove anonymous users, disable remote root login, and remove test databases.

Log in to MySQL using the root user:

sudo mysql -u root -p

Create a new database and user for WordPress:

CREATE DATABASE wp_database;
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

Step 3: Download and Configure WordPress

Download the latest version of WordPress from the official website:

cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar xzvf latest.tar.gz
sudo cp -r /tmp/wordpress/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html/

Copy the sample configuration file and edit it:

cd /var/www/html/
sudo cp wp-config-sample.php wp-config.php
sudo nano wp-config.php

Update the database settings:

define('DB_NAME', 'wp_database');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');

Save and exit the file.

Step 4: Complete the Installation

Open your web browser and navigate to your server's IP address or domain name. Follow the on-screen instructions to complete the installation of WordPress.

Conclusion

You have successfully installed WordPress on your VPS. You can now create and publish your content and customize your website using themes and plugins.