770-778-3976 trey@codeschneider.com

This post will show you how to run multiple WordPress installations on a single server.

Not too long ago, when I needed to deploy a new WordPress site, I would login to Digital Ocean and launch a new $10/droplet via their one-click WordPress installation. This process worked great. But before long I was spending a lot of money every month, and I noticed every WordPress website still had plenty of memory and CPU to spare.

I thought there must be a better way, and there is: Apache Virtual Hosts.

With Apache Virtual Hosts, you can run multiple WordPress installations on a single server. This tutorial assumes that you are running Apache on an Ubuntu >14.04 VPS.

Apache divides its functionality into small building blocks, and each building block is called a virtual host. Each virtual host can be configured differently from one another. As you will see below, by configuring multiple virtual hosts, we can run multiple WordPress installations from a single host.

If you haven’t installed Apache yet, you can do so by apt-get:

sudo apt-get update
sudo apt-get install apache2

In this tutorial, we will setup virtual hosts for two domains, example1.com and example2.com.

Step 1 – Create Directory Structure on your Server

Under /var/www, create a directory for each of our sites along with a subdirectory called html which will hold each site’s content:

mkdir -p /var/www/example1.com/html
mkdir -p /var/www/example2.com/html

Step 2 – Set Permissions

The html directories we just created are owned by the root user. We need to allow a regular user to be able to modify files within these directories. Do so with the following commands:

sudo chown -R $USER:$USER /var/www/example1.com/html
sudo chown -R $USER:$USER /var/www/example2.com/html

We also want to give read access to everything within /var/www:

sudo chmod -R 755 /var/www

Step 3 – Transfer WordPress Content to each Virtual Host

Now it’s time to add your content! Install WordPress within the the /var/www//html directory (see this post on how to manually install WordPress) and then migrate your existing WordPress content to the new installation (see this post on how to easily migrate a WordPress website).

Step 4 – Create Virtual Host Files

Our virtual host files will be the configuration that instructs our host on how to respond to certain domain requests.

Every Apache installation comes with a default virtual host file called 000-default.conf. Let’s copy this file and use it to create our custom virtual host files:

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example1.com.conf

Now open the example1.com.conf file in your terminal text editor, we will use vim:

vim /etc/apache2/sites-available/example1.com.conf

First, we need to change ServerAdmin directive to an email that the actual server admin can receive emails at, for example:

ServerAdmin your-name@example1.com

Now, we need to add two more directives, ServerName and ServerAlias. ServerName will be your domain name, and ServerAlias will be any other names that should match for this WordPress site, such as www.example1.com:

ServerName example1.com
ServerAlias www.example1.com

Lastly, make sure the DocumentRoot directive matches your domains directory structure:

DocumentRoot /var/www/example1.com/html

Repeat this step for the other domain, example2.com, or any other domains you wish to host on your machine.

Step Five — Enable the Virtual Host Files

We created the new virtual host files, but now we need to ‘turn them on’. We can use a utility called a2ensite to accomplish this:

a2ensite example1.com.conf
a2ensite example2.com.conf

Now restart Apache:

service apache2 restart

Step Six – Point your Domains to your New IP Address

You will need to add an A record to your DNS file(s) in order to point your domain(s) to your new host’s IP address.

Try accessing each of your domains via a web browser and see if your sites are rendering properly.

If not, ask a question in the comments and I will get back to you ASAP.

Thanks,
Trey

Pin It on Pinterest

Share This