ManagedCloud Servers

High performance handled and monitored by us 24/7/365. A complete solution to provide you with our in house expertise 24/7 tailored to your specific needs. We'll setup a bespoke server for your site using the latest tehnologies so you can get the most out of your hardware and get your website loading quickly and reliably. Find out more..

cPanelCloud Servers

Recommended - High performance cloud servers with no technical knowledge required. If you're hosting multiple websites already and you're looking to consolidate, or if you're looking to isolate yourself from the shared hosting environment but you don't have the time or knoweldge to manage a server, then the Managed cPanel Servers are for you. Find out more..

UnmanagedCloud Servers

Our unmanaged range gives you complete control at rock bottom prices and our cloud platform boasts super fast multipath 40Gb/s network, the latest Intel Xeon V3 CPUs and enterprise grade redundant SSDs. If you're a sysadmin look no further, we offer some of the best specification to price ratio servers available. Find out more..

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting from £1.60 / month

View Plans

How to Deploy Multiple WordPress Sites on a Single Ubuntu 16.04 Host

Wordpress is the most well known CMS (content management system) that can be used to create a beautiful website, blog, or application on the Internet. It is completely free and open-source application based on PHP and MySQL.

In this tutorial, we will learn how to host multiple wordpress instances on a single Ubuntu host.

Requirements

  • A server running Ubuntu 16.04.
  • A non-root user with sudo privileges configure on your server.

Update System

Before starting, you will need to update Ubuntu repository with the latest one.

You can do this by running the following command:

sudo apt-get update -y sudo apt-get upgrade -y

Installing LAMP

Next, you will need to install LAMP stack as a prerequisite of Wordpress. You can install it with the following command:

sudo apt-get install apache2 mariadb-server php7.0-mysql php-xml php7.0-curl php7.0-json php7.0-cgi php7.0 libapache2-mod-php7.0

Downloading Wordpress

You can download the latest version of wordpress from it's official website http://wordpress.org/.

You can also download it with the following command:

wget http://wordpress.org/latest.tar.gz

Once download is complete, extract the downloaded file with the following command:

tar -xvf latest.tar.gz -C /tmp

Next, copy sample configurtion file:

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

Next, create a directory for each wordpress site inside web root directory:

sudo mkdir /var/www/html/Site1/ sudo mkdir /var/www/html/Site2/

Next, copy the content of wordpress directory to site1 and site2 directory:

sudo cp -avr /tmp/wordpress/* /var/www/html/Site1/ sudo cp -avr /tmp/wordpress/* /var/www/html/Site2/

Next, change the ownership of the directories to the Apache web user:

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

Configuring the Database

The default Mariadb installation is not secure, so you will need to secure it first. You can secure it using mysql_secure_installation script:

sudo mysql_secure_installation

Once, database is secured. You will need to configure an independent database and user for each wordpress site.

To do so login to mysql with the follwing command:

mysql -u root -p

Enter your root password, you will be dropped into a MySQL prompt.

Create the two database for each site:

MariaDB [(none)]>CREATE DATABASE SITEDB1; MariaDB [(none)]>CREATE DATABASE SITEDB2;

Next, create a user for each site:

MariaDB [(none)]>CREATE USER User1@localhost; MariaDB [(none)]>CREATE USER User2@localhost;

Next, setup password for each user:

MariaDB [(none)]>SET PASSWORD FOR User1@localhost=PASSWORD("password"); MariaDB [(none)]>SET PASSWORD FOR User2@localhost=PASSWORD("password");

Next, granting privileges to the new users:

MariaDB [(none)]>GRANT ALL PRIVILEGES ON SITEDB1.* TO User1@localhost IDENTIFIED BY 'password'; MariaDB [(none)]>GRANT ALL PRIVILEGES ON SITEDB2.* TO User2@localhost IDENTIFIED BY 'password';

Finally flush the privilege information to implement the changes:

MariaDB [(none)]>FLUSH PRIVILEGES;

Then, exit from the MySQL shell:

MariaDB [(none)]>exit

Once database is configured, you can proceed to the next step.

Configure Wordpress

Next, you will need to configure wordpress for each site.

Configure Site1

You will need to specify database, username and password in wp-config.php file:

To do so open wp-config.php file:

sudo nano /var/www/html/Site1/wp-config.php

Make some changes as shown below:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'SITEDB1');

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

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

Once you are done, close the file.

Configure Site2

You will need to do same procedure as above.

Open wp-config.php file:

sudo nano /var/www/html/Site2/wp-config.php

Make the changes as shown below:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'SITEDB2');

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

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

Save and close the file, when you are finished.

Configuring Apache Virtualhost

You will need to configure virtual host configuration file for each wordpress site.

Configure Virtualhost for Site1

You can configure Apache virtualhost by creating site1.conf file:

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

Add the following line:

<VirtualHost *:80>
    ServerAdmin admin@site1.com
    ServerName site1.com
    ServerAlias www.site1.com

DocumentRoot /var/www/html/Site1 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/html/Site1> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>

Save and close the file. Then, enable virtualhost by running the following command:

sudo a2ensite site1.conf sudo systectl apache2 restart

Configure Virtualhost for Site2

You can configure Apache virtualhost by creating site2.conf file:

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

Add the following line:

<VirtualHost *:80>
        ServerAdmin admin@site2.com   
        ServerName site2.com
        ServerAlias www.site2.com

DocumentRoot /var/www/html/Site2 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/html/Site2> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> </VirtualHost>

Save and close the file. Then, enable virtualhost by running the following command:

sudo a2ensite site2.conf sudo systectl restart apache2

Installing Required Modules

You will also need to install an extra PHP module installed in order to wordpress function correctly.

You can do this by installing php7.0-gd module:

sudo apt-get install php7.0-gd

Finally, reload Apache so that it reads your changes:

sudo systemctl restart apache2

Accessing Site1

Once everything is ok, it's time to access both wordpress sites.

To access site1, Open your favourite web browser and type the URL http://site1.com, you will see the following page:

Choose the language as English and press Continue button, you should see the following page:

Next, fill up all the details like username, password, email then press the Install Wordpress button. This will install wordpress for Site1 on your server.

To access site2, Open your favourite web browser and type the URL http://site2.com, you will see the following page:

Choose the language as English and press Continue button, you should see the following page:

Next, fill in all the details like username, password, email then press Install Wordpress button. This will install wordpress for Site2 on your server

You can now easily login and configure each site as you wish.

Conclusion

Congratulations! you have successfully installed and configured multiple wordpress instances on a single Ubuntu 16.04 server. You can now easily deploy it in a production environment.

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting from £1.60 / month

View Plans