// Tutorial //

How To Set Up Multiple WordPress Sites on a Single Ubuntu VPS

Published on August 21, 2013
Default avatar
By Justin Ellingwood
Developer and author at DigitalOcean.
How To Set Up Multiple WordPress Sites on a Single Ubuntu VPS

Status: Deprecated

This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.

See Instead:
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.

Introduction

WordPress is a popular CMS (content management system) that can help you get your site off of the ground quickly and easily. Sometimes, you need to host multiple, unrelated sites on the same server.

This guide will cover how to host two separate WordPress instances on one VPS. They will each have their own domain name. This is different from setting up multisite.

We will accomplish this through the use of virtual hosts. This guide will use an Ubuntu 12.04 VPS server, but other distributions should function in a similar way..

Prerequisites

This guide has a few requirements that are covered in-depth in some of our other articles. Before you begin, make sure you have completed the following:

At this point, you should have LAMP installed on Ubuntu and both of your domain names should be pointing to your droplet.

Ensure that this is the case by visiting your domain names in a web browser. Both domains should give you the same default Apache index page:

Default Apache index page

If your domains do not lead to this page, then either you need to wait for the DNS changes to propagate, or you have misconfigured something in the previous steps. Do not continue until this is resolved.

Download Wordpress

When you are ready, log into your server and change to your home directory. We will download the files here:

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

Unzip and decompress the archive file by issuing the following command:

tar xzvf latest.tar.gz

Create Site Databases and Users

Before we continue, we need to configure an independent database and user for each site within MySQL. This will ensure that the site data is separate.

For the purposes of this guide, we will be using the following information:

Site Name firstsite.com secondsite.com
Database Name FirstDatabase SecondDatabase
Database User FirstUser SecondUser
Database Password FirstPassword SecondPassword

The table above is provided to give you context for the commands we will be using. Substitute your own information when you are filling out the commands that follow.

Log into MySQL using the administrator account you configured during the MySQL installation:

mysql -u root -p

You will be prompted for the MySQL root password and then you will be dropped into a MySQL prompt.

Create the two databases with the following commands:

CREATE DATABASE FirstDatabase;
CREATE DATABASE SecondDatabase;

Create a user that will be associated with each database:

CREATE USER FirstUser@localhost;
CREATE USER SecondUser@localhost;

Next, set up the password access for each account:

SET PASSWORD FOR FirstUser@localhost= PASSWORD("FirstPassword");
SET PASSWORD FOR SecondUser@localhost= PASSWORD("SecondPassword");

Finish up by granting privileges to the new users. This associates the database users with their respective databases and grants them appropriate permissions:

GRANT ALL PRIVILEGES ON FirstDatabase.* TO FirstUser@localhost IDENTIFIED BY 'FirstPassword';
GRANT ALL PRIVILEGES ON SecondDatabase.* TO SecondUser@localhost IDENTIFIED BY 'SecondPassword';

Refresh MySQL's privilege information to implement the changes:

FLUSH PRIVILEGES;

Exit out of MySQL to return to the shell session:

exit

Configuring Site Root Directories

We will be installing both of the sites within individual directories in the web root of our server.

Change to the "/var/www/" directory:

cd /var/www

Create a directory for each of our sites. These will store the site files:

sudo mkdir FirstSite
sudo mkdir SecondSite

Copy the sample configuration before we move the web contents into our folders:

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Finally, copy the files to the directories you created under the web root of the server:

sudo rsync -avP ~/wordpress/ /var/www/FirstSite/
sudo rsync -avP ~/wordpress/ /var/www/SecondSite/

Give ownership of the directories to the Apache web user and then add your linux username to the web group:

sudo chown www-data:www-data * -R
sudo usermod -a -G www-data linux_user_name

WordPress Configuration

We will configure each site with the information about our sites.

First Site Configuration

Change directories to the first site's document root:

cd /var/www/FirstSite

Open the WordPress Configuration file for editing:

sudo nano wp-config.php

Find the section that contains the fields below and substitute the database, username, and password for your first site:

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

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

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

Save and exit.

Second Site Configuration

Change directories to the second site's document root:

 cd /var/www/SecondSite

Open the WordPress Configuration file for editing:

sudo nano wp-config.php

Find the same section you edited for the previous site. You will be entering information for the second site this time.

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

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

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

Save and exit.

Apache Virtual Host Configuration

We need to configure Apache to direct traffic from each domain to their respective directories. We will do this by creating separate virtual host files for each domain.

Change the directory to Apache's available sites directory:

cd /etc/apache2/sites-available

Create a new virtual host file for each site by copying the default virtual host file:

sudo cp default FirstSite
sudo cp default SecondSite

First Site Virtual Host Configuration

Open the first file you copied to configure the virtual host for the first site:

sudo nano FirstSite

Change the information in the file to match the following. Remember to substitute the information in red to match your first site:

<VirtualHost *:80>
	ServerAdmin your_email_address
	ServerName firstsite.com
	ServerAlias www.firstsite.com
	
	DocumentRoot /var/www/FirstSite
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/FirstSite>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
. . .
. . .

If you need to enable pretty permalinks, you can change the "AllowOverride None" within the "<Directory /var/www/FirstSite>" block to "AllowOverride All". You can learn more about the requirements for pretty permalinks here.

After making the changes, save and close the file.

Second Site Virtual Host Configuration

Open the second virtual host file for editing:

sudo nano SecondSite

Change the information to reflect your second site's information:

<VirtualHost *:80>
	ServerAdmin your_email_address
	ServerName secondsite.com
	ServerAlias www.secondsite.com
	
	DocumentRoot /var/www/SecondSite
	<Directory />
		Options FollowSymLinks
		AllowOverride None
	</Directory>
	<Directory /var/www/SecondSite>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>
. . .
. . .

Save and close the file.

Final Configuration

There are a few more steps necessary to get our sites working.

First, WordPress needs an extra PHP module installed in order to function correctly. Install it by typing:

sudo apt-get install php5-gd

Next, enable the virtual host files that we created by typing:

sudo a2ensite FirstSite
sudo a2ensite SecondSite

Finally, reload Apache so that it reads our changes:

sudo service apache2 reload

Seeing the Results

In order to see your new WordPress sites, simply navigate to your domain names in a web browser.

If you have configured everything correctly, you should be greeted by a page that looks like this:

WordPress Initial Login

You can now log in and configure each site independently. These sites are completely separate and can be administered as if they exist on two entirely different VPS servers.

By Justin Ellingwood

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in our Questions & Answers section, find tutorials and tools that will help you grow as a developer and scale your project or business, and subscribe to topics of interest.

Sign up
About the authors
Default avatar
Developer and author at DigitalOcean.

Still looking for an answer?

Was this helpful?
10 Comments

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

I just followed this tutorial on Ubuntu 14.04. Everything went well, although I needed to give the virtual host files a “.conf” extension.

I made a copy of the /etc/apache2/sites-available/000-default.conf file and named it site1.conf and site2.conf

Thanks for a very helpful tutorial!

sudo cp default FirstSite 

does not work. but below worked.

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

thank you.

I am getting ERROR: Site mySite does not exist! while executing following command

sudo a2ensite mySite

from location

/etc/apache2/sites-available

Also since sudo cp default file doesn’t exists, alternatively I copied 000-default.conf from /etc/apache2/sites-available.

The part where you copy the default apache virtual host file needs to be updated.

You have it as:

Create a new virtual host file for each site by copying the default virtual host file:

sudo cp default FirstSite sudo cp default SecondSite

It should be

Create a new virtual host file for each site by copying the default virtual host file:

sudo cp 000-default.conf FirstSite sudo cp 000-default.conf SecondSite

In ubuntu 13:10 or later the .conf needs to be included also

these steps are not working with Ubuntu 14.04. could you please create a tutorial for Ubuntu 14.04 users?

Thanks Andrew. That worked for me. The next command in this guide should also be changed to:

sudo nano FirstSite.conf

instead of

sudo nano FirstSite

@abdoberndt: Use:

<pre> sudo cp 000-default.conf FirstSite.conf sudo cp 000-default.conf SecondSite.conf </pre>

@abdoberndt: Are you on Ubuntu 14.04? If so, that file was rename <code>000-default.conf</code>

Would it not be better to change the ownership/permissions as so:

sudo chown _R $USER:www-data *

Where $USER is the non-root user you use to FTP/SFTP and * is the directory such as /var/www/domain.com/htdocs.

It doesn’t seem a good idea to me to have Apache user (www-data) own the files. It would seem better to chown as above and then change the permissions on directories and files as follows:

Directories: 755 Files: 644

In specific cases where Apache needs to write to directories and files (such as in wp-uploads, the .htaccess file and wp-config) then change the files to 664 and directories to 775.

I can’t think why that setup wouldn’t work and it would seem a more ‘secure’ setup, with Apache limited in it’s write access to only the files it needs.

Temporary changes could be permitted as needed to allow Wordpress auto updates by temporarily setting:

sudo chown _R www-data:www-data *

…and then changing back once done. Yes it’s slightly more work (a couple commands) but it seems it would be a ‘safer’ setup, right?

Hi there,

You could also follow the steps from this video on how to host multiple WordPress websites on the same server with Apache Virtual Hosts:

Hope that this helps. Regards, Bobby