How to Set Up an Ubuntu VPS with WordPress

WordPress is incredibly popular with users due to its simplicity and ease of use. It allows anyone (from beginner to expert) to create responsive and SEO-friendly mobile sites that are both high-performance and secure with or without using any programming skills. Millions of people are using it to power their personal websites, professional websites, blogs, stores, forums, galleries, and just about anything you could imagine. If you are looking for a simple yet powerful CMS for your next website then WordPress should be the first on your list. In this step-by-step tutorial, we are going to explain how to set up a Linux VPS (Ubuntu) and install WordPress on it.

System Requirements

Before we get going, you must know what WordPress requires to work without any problems. These are the system requirements:

  • Ubuntu VPS with SSH access
  • PHP 7 or greater
  • MySQL 5.6 or greater OR MariaDB 10.0 or greater
  • Apache with mod_rewrite module enabled

Apache, MySQL/MariaDB, and PHP are all part of the famous LAMP stack that powers most of the modern sites today. Follow the steps below to set up a LAMP stack on your Ubuntu VPS and install WordPress. If you’ve used cPanel shared hosting before, then you are probably somewhat familiar with the LAMP stack.

Update the System

Connect to your Ubuntu VPS and update all of your currently installed software to the latest version available. This will ensure that your system is both secure and optimized for the best performance. You should update your system on a regular basis, or set up automatic updates.

sudo apt-get update
sudo apt-get upgrade

Install Apache, MySQL, and PHP

To install Apache, run the following command on your server:

sudo apt-get install apache2

Create a virtual host for the new WordPress site. Replace with your actual domain name in the examples below.

You can use the editor of your choice. In this tutorial, we’ll use nano. If you don’t have nano installed, you can do so with the following command:

sudo apt-get install nano

After you’ve installed nano, run:

sudo nano /etc/apache2/sites-available/

And paste the following lines:

<VirtualHost *:80>
 DocumentRoot /var/www/html/

 <Directory /var/www/html/>
 	Require all granted
 ErrorLog /var/log/apache2/
 CustomLog /var/log/apache2/ common

Save the changes and close the file.

Next, create a directory for your website data:

sudo mkdir -p /var/www/html/

To enable the new virtual host, run the following command:

sudo a2ensite

Then, reload Apache for the changes to take effect:

sudo systemctl reload apache2

Now it is time to install MySQL. Run the following command to install the MySQL database management system:

sudo apt-get install mysql-server

Once the installation is completed, you can use the mysql_secure_installation script to improve the security of your database system. Follow the script’s prompts, and answer the questions.

The last component of the LAMP stack is PHP. We’ll use PHP 7 instead of the older versions for the speed, security, and all other improvements. To install PHP 7 and all other required PHP 7 modules on your Ubuntu server, run the following command:

sudo apt-get install php7.0 php-pear libapache2-mod-php7.0 php7.0-opcache php7.0-mysql php7.0-cgi php7.0-curl php7.0-mcrypt php7.0-mbstring php7.0-json php7.0-cgi php7.0-xml

Now that you have the basic install of the LAMP stack, you can proceed to install WordPress.

Install WordPress

To install WordPress on your Ubuntu server, navigate to the document root for your domain name and download the latest version of WordPress:

cd /var/www/html/

Extract the archive and move the files:

mv wordpress/* /var/www/html/

You may need to install wget and unzip on your server. If you do have to do that, run the following command to install them:

sudo apt-get install wget unzip

Now, create a MySQL database and user for your WordPress site. Log in to MySQL as root:

mysql -u root -p

Replace the value for the password with your own value and run the following commands one by one:

mysql> CREATE DATABASE wordpressdb;
mysql> GRANT ALL PRIVILEGES on wordpressdb.* to 'wordpressuser'@'localhost' identified by 'PaSsW0rD';
mysql> EXIT

Create a WordPress config file:

cp /var/www/html/ /var/www/html/

Edit the newly created config file and change the MySQL settings:

/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'PaSsW0rD');

Next, change the file permissions:

sudo chown -R www-data: /var/www/html/

Now, open your favorite web browser and enter your domain name into the address bar. You will see the WordPress welcome page where you can select the default language and set up the basic info for your site.

And you are done! You have successfully set up an Ubuntu VPS with WordPress.

You can now continue with some other configurations and optimizations on your Ubuntu server. If you haven’t already, you should secure your server. Installing a firewall is a must. If you don’t know how to manage a server, you can get Managed VPS hosting (use coupon code WHS50 to get 50% off your first payment when paying monthly), and have the hosting provider do all of this for you.