• Get In Touch
December 15, 2016

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

Using Wordpress? Get our lightening fast Wordpress Optimised Hosting.
Get Wordpress Hosting

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:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/253908648.png” alt=”” />

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

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/896255709.png” alt=”” />

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:

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/130606654.png” alt=”” />

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

HP_NO_IMG/data/uploads/users/7ecb43a5-b365-4ebf-93d5-f3b632f29f33/1309526149.png” alt=”” />

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.
Get Wordpress Hosting

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]