WordPress Multi-site Servers on Production Machines

Press me to get started

Press me to get started

Everybody knows how to set up a LAMP machine and get a WordPress site running, using the famous three-minute installation. But how many of you can actually get WordPress 3’s new multi-site capability running in the same amount of time? Okay, three minutes is not a realistic goal, but how about setting up a production WordPress Networked Site (that’s what they call the multi-site functionality) in under 30 minutes? Fair enough?

Let me cut right to the chase: we will create a server that hosts multiple WordPress blogs, using one single installation of WordPress — somewhat like your own personal version of WordPress.com. Obviously, while what I’m about to describe here won’t help you run a WordPress.com clone and make money, it will be good enough to run your corporate or university blog server that faces the full wrath of the Internet.


We will run the following:

  • Operating system: We will use Ubuntu 10.04.2 LTS (that’s the latest revision of 10.04 LTS; revision 3 will be making its appearance in the end of July this year).
  • Apache Web server: The HTTP server.
  • MariaDB database server: This is a fork of MySQL that has a couple of enhancements, apart from being free of all the Oracle cruft. You can use vanilla MySQL though, if you wish.
  • PHP… obviously.

The MariaDB database server

MariaDB is a commercially supported community fork of MySQL, which comes with a few enhancements. Note, however, that MariaDB does not support MySQL NDB clustering yet, which might make it an unattractive bet for super-large blog hosts (such as your multi-million-dollar WordPress.com competitor).

You’ll need to use a third-party repository for MariaDB. You can just leave MariaDB out if you don’t trust it (and use vanilla MySQL instead), but I’d recommend using MariaDB.

Let’s get to it!

Start by installing a vanilla Ubuntu 10.04.2 LTS Server (using whatever means are at your disposal, be it a CD, DVD, USB drive or even a NetInstall). Just set up the operating system — install no optional packages (except the SSH server if you want to). Do not install a Web or database server at this point. Update the operating system, reboot, drop to a shell prompt, and begin the setup process.

Installing the server software

We will start by installing the database server, and then securing it. We will first need to add the MariaDB repository, and the associated GPG key, to the package-management system. If you want to use vanilla MySQL, skip these steps, and install the mysql-server and mysql-client packages instead of the mariadb counterparts. Anyway, to go ahead with MariaDB, first create a file called /etc/sources.list.d/mariadb.list in a text editor, and append the following two lines in it:

deb http://mirrors.xmission.com/mariadb/repo/5.1/ubuntu lucid main
deb-src http://mirrors.xmission.com/mariadb/repo/5.1/ubuntu lucid main

Since Ubuntu 10.04.2 uses MySQL 5.1 by default, introducing 5.2 into the system is going to break some ABIs. For this, we’ll have to use the 5.1 branch of MariaDB, which is based on MySQL 5.1.

Now to add the GPG key, type the following:

sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 1BB943DB

Right, so we have got the infrastructure set up. Now, run the following commands:

sudo apt-get update
sudo apt-get install mariadb-server mariadb-client

These packages “provide” mysql-server and mysql-client, so that won’t mess up your package manager. Great! We have a DB server on the system. However, this is a production server, so just having a server will not do; we will have to secure this thing. Type in:


Run through this script. Once you do that, the server will be secure enough to run on a production system. Your database server should be all set; however, if you are running vanilla MySQL there’s room for more optimisations. Open up /etc/mysql/my.cnf, and add in the following single line:


Once this is done, restart the MySQL server, and continue to the next stage.

The HTTP server and PHP interpreter

Type in:

sudo apt-get install php5-cgi php5-mysql apache2 libapache2-mod-php5

This will install the Apache Web server and the PHP 5 interpreter. You will now be able to install WordPress and configure a network of sites.

Installing WordPress

Assuming you have now unpacked the WordPress tarball into Apache’s web root (/var/www by default), you should be able to start with the initial setup of WordPress. You will have to set up a normal WordPress site before you can enable Network, so let’s start with the initial setup now.

First, we will have to prepare MariaDB/MySQL, by creating a database and assigning credentials to it, so that WordPress can set itself up. Type in:

sudo mysql -u root -p

Type your MySQL root password. You will now be dropped into the MySQL shell. To create the database and assign a user to it, type in the following:

GRANT ALL PRIVILEGES ON wp_network.* TO wp_user@localhost IDENTIFIED BY 'wp_password';

The last statement will quit the MySQL shell. Remember to change the database name, user name and password to something else, for security’s sake.

Now, open up http://localhost in a Web browser, and step through the WordPress installation wizard. When you’re asked for database details, ensure you use the credentials that you gave when you created the database in the MySQL shell. Do not even think about using the root credentials — you’ll risk getting your entire server cracked that way.

Now that you have the WordPress admin user details, test basic WordPress functionality. If it works, it’s time to move on to the big thing: enabling Network.

WordPress Network

WordPress Network functionality depends on .htaccess files, and mod_rewrite. Due to its complete reliance on htaccess it is very difficult to get a WordPress network running on servers other than Apache. Anyway, there are two ways in which WordPress 3.0 Networks can be defined: Subdirectory and Subdomains.

In Subdomain mode, every subdomain of your master WordPress domain redirects to a different site. It’s like your own version of WordPress.com. In Subdirectory mode, as you have no doubt guessed by now, every site resides in its own directory.

Will it work?

If you want to get a Subdirectory-based Network running, all you need is enough configuration to get fancy permalinks working — and this is enabled by default in Ubuntu’s Apache.

If you want a Subdomain-based Network running, however, the setup is a lot more involved, as it requires you to set up a Virtual Host in Apache, and wild-card Domains in your DNS server.

In this article, we will set up a Subdomain-based Network. I assume you have your DNS server up and running somewhere in your organisation, so you will just need to ask your sysadmin to add a certain DNS record.

Getting started with a Subdomain Network configuration

The first step, of course, is adding a wild-card DNS record to your DNS server, which is shown below:

*.example.com.	3600	A

…or, in shorthand:

*			3600	A

Replace example.com and the IP address with your own domain and IP address. Your DNS is now configured.

Next, we will have to hack the Apache configuration to support wild-cards. Open up your /etc/httpd.conf file, and search for the DocumentRoot line. Right under that line, add the following code snippet:

ServerAlias	*.example.com

Again, replace example.com with your domain name. Save the file and quit. This concludes the server software part of the setup. Now, we will move on to configuring WordPress itself.

Enabling Network in WordPress

Start by editing the wp-config.php file in the root of your website. Just above the line that says /* That's all, stop editing! Happy blogging. */, add the following code:

define('WP_ALLOW_MULTISITE', true);

Now log in to WordPress Administration. In the Administration sidebar, under Tools, you will see a new item called Network. Click on it.

In this screen, all the data will be filled in automatically, but just in case you want to change anything (you will only be allowed to change your email address and the name of the Network), go ahead and do so, and then hit Install.

Let it run through everything, while it checks and enables Network functionality. Finally, you will be shown a screen that will ask you to do a couple of things, roughly in the following order:

  1. Create a blogs.dir directory under the wp-content directory of your website.
  2. Add a couple of lines to your wp-config.php file (The lines will be given; you will just have to copy and paste them.)
  3. Add some mod_rewrite rules to your htaccess file, overwriting any existing configuration (again, the generated lines will be given; you will just have to copy and paste).
  4. Click the Log In link at the bottom of the page to log in again, thus rendering the Network functional.

Now, what if you wanted to set up a Subdirectory-based network? When you entered the Network screen in WordPress Administration, you must have noticed that you were given a choice between Subdomain and Subdirectory (unless some sort of configuration error was preventing you, in which case, the cause was stated on the page). You can select the type from that screen itself. In addition, if you want a Subdirectory-based Network, you won’t have to tinker with the DNS records and the ServerAlias line in Apache.

Where to go next

Now that you have the setup running, where do you go from here? For starters, have a look at this WordPress Codex article for information that will help you run and modify your Network.

The next step would be to create a few sub-blogs. If you already have blogs that you would like to import into your new Network, visit this Codex article to learn how to do that.

Well, that’s about it. Enjoy your new multi-site :-)


Please enter your comment!
Please enter your name here