Wordpress 3.0 is coming out very soon (apparently they missed their original deadline, see the schedule here) - and it has one killer feature for anyone who maintains multiple Wordpress sites: official support for multiple subdomains and (unofficial) support for multiple different domains. This means that one only has to maintain and upgrade one Wordpress installation.

Here is my guide to setting up Wordpress 3.0 with multiple different domains and subdomains - based on the experience I got from moving my own blogs to WP 3.0 beta 2 (still waiting for the final release before moving clients as well).

Installing Wordpress 3.0

The basic installation process is the same as that of WP 2.9. Download, unzip, set up the database and the set up wp-config.php. If you aren't going to use the multi-site support, then not much will change. Brief instructions below.

Multi-site mode with Apache

You will need to separately enable the multi-site mode, as well as take care of your Apache settings. WP 3.0 will handle all the requests it gets from a single directory, which means that all your subdomains must use that directory as their DocumentRoot/VirtualDocumentRoot.

Furthermore, WP 3.0 will assume that if you are using multi-site mode with subdomains, you want the subdomains under the first site's URL - ex. if your first WP 3.0 install is under www.domain.com, then WP 3.0 will set up subdomains in the format subdomain1.www.domain.com.

That means that if you want to use first-level subdomains (ex. blog.domain.com, subdomain2.domain.com etc.), you have to set up WP 3.0 so that your first blog is using the bare domain (ex. domain.com) and not on the www.domain.com subdomain.

0. (Optional) Bare domain setup for Apache

The way in which you setup your bare domain (and forward from the www -subdomain to the bare domain) depends a lot on how you have set up your domain originally in Apache.

I have been using virtual hosts to host multiple sites, with each subdomain having its own directory. This means that I had to add an additional Vhost directive before my original Vhost directive in httpd.conf. Here is how I did it:

    ServerName domain.com
    ServerAlias domain.com blog.domain.com subdomain1.domain.com
    DocumentRoot /var/www/domain.com/www
As you can see in the first Vhosts directive, I have used the ServerAlias directive to specify domain.com, blog.domain.com and subdomain1.domain.com to be served from the DocumentRoot /var/www/domain.com/www (which is where I have installed WP 3.0).

In addition, I still have the rest of my subdomains served from a VirtualDocumentRoot, and have a forward from the www.domain.com -subdomain to the domain.com bare domain.

    ServerName domain.com
    ServerAlias *.domain.com
    VirtualDocumentRoot /var/www/domain.com/%1

# rewrite www to bare domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule (.*) http://domain.com$1 [R=301,L]</pre>

Apache will use the first matching VirtualHost directive (see "An in-depth discussion of Virtual Host Matching" for more details).

If you want to test your setup - remember to restart Apache - you can use an online redirect checker such as: http://www.internetofficer.com/seo-tool/redirect-check/

1. Get the files and unzip them

2. Edit wp_config_sample.php

You can use https://api.wordpress.org/secret-key/1.1/salt/ to generate the secret keys

3. Enable multisite

Add:

 define(’WP_ALLOW_MULTISITE’, true);
to wp-config.php after the secret keys

4. Log in, go to Tools/Network

Select either the blogs-as-subdomains or blogs-as-directories option and install.

5. Make the changes detailed on the post-install page

WP 3.0 gives you a number of changes you will need to make manually to .htaccess and wp-config.php.

Adding a new subdomain

You have now set up the multisite functionality. Next, add a subdomain (see below for how to add a different domain).

1. Login in on your main site

2. Go to Super Admin (new menu at the top)

3. Use the add site form to add a new subdomain

4. Configure your DNS and add a Vhost for the subdomain

Make sure there is a DNS entry for your subdomain - if you don't have a wildcard redirect for your domain to your server. If you did the Apache configuration, all you need to do now is to set up your DNS so that the subdomains you want are mapped to your server.

Quick tip for Windows: edit C:WindowsSystem32driversetchosts and add a temporary hosts entry for your new subdomain, such as:

123.14.15.16 subdomain.domain.com

This will allow you to test the subdomain without having to wait for DNS to propagate. Under Win7, you need to start Notepad as an Administrator (right-click) to edit the file.

5. All done!

Try navigating to your new subdomain. It should be set up now!

Adding a new (different) domain

1. Use the add site form to add a new subdomain

You will use the default tools to create all the tables, then you will make a small number of changes to make Wordpress accept a different domain. All credit for this method goes InterconnectIt - see their writeup here.

2. Configure your DNS and add a Vhost for the subdomain

The easiest way is to add another ServerAlias domain to the original domain's VirtualHost -> ServerAlias directive.

If you try to access the site now, you will get a "Registration" page. This means the Vhost is working.

3. Edit the wp_site table to include your new domain

This table stores all the domains that can be used in WP 3.0.

Leave "id" empty (it is an autoincrement field), set "domain" to the domain name, "path" should be /.

Make a note of the id your newly inserted row gets after saving, since you will need it in the next step.

4. Edit the wp_blogs table to use the new domain

Find the row for the subdomain you added earlier. Change "site_id" to the id given to the new row in the wp_site table. Change "domain" to the domain name you want to use.

5. Edit wp[blog_id]_options to use the new domain name

The WP 3.0 multisite database schema is sharded by having the blog id in the table names. By default these are in the form wp[blogid]*, so you will need to find which set of tables contains your new blog.

Each Wordpress blog stores a small number of settings which need be changed to use the new domain name. You can use the query below to find the mentions of the domain in the options table:

SELECT * FROM wp_[blog_id]_options WHERE option_value LIKE "%subdomain.domain.com%";

For me these are: siteurl, home, fileupload_url. Change them to use the new domain.

6. Done!

Do you need to move an existing WP 2.9 to WP3.0 multisite? If you are moving an existing site to the WP multisite you've set up, check out my second tutorial on the topic.

Did you run into problems enabling themes or plugins on your separate domains? Have a look at how I solved a number of issues related to the separate domains setup.

References

  1. http://www.interconnectit.com/840/wordpress-3-0-multisite-with-multiple-domains-setup/

Comments

Jeff: Hi,

I've followed all these steps, and successfully setup a completely separate domain (like www.johnny.com) to display a second blog setup in WP 3 (originally setup using subdomains, like johnny.mysite.com).

After this success however, my super admin cannot see the new site in Super Admin>Sites, nor can I login when going to the new wp-admin section (like www.johnny.com/wp-admin) using this super admin.

Have you found this to be the case as well?

Mikito Takada: Yes, after using a separate domain the site is no longer listed my Super Admin->Sites section. I expect that the interface will be improved in future releases of Wordpress 3.

However, I have been able to use the Super admin login on the alternate domain's /wp-admin/ and administer it normally. Another slight problem with separate domains was that user registration links were not shown, but I'm not sure whether that is an issue with the Twenty-Ten theme or with the core. If you can't use the alternate domain with the super admin login, have a look at what the wp_capabilities field in wp_users says.

Jeff: Mikito,

Thanks for the tips, I just figured out that you can go in via Super Admin > Sites, and change the domain name to whatever you want. As long as your DNS and Apache is configured correctly, you don't have to change any database tables. Super easy!

-Jeff

Mikito Takada: It seems indeed that you can change the domain under Super Admin -> Sites BUT it does not change the fileuploadurl option in wp[blog_id]_options.

And if you don't do the wp_site and wp_blogs table editing, it's not possible to log in as administrator - this is with the current nightly.

But this problem only appears if you are using separate domains.

Jon Henshaw: This is what I've been using: How to Easily Manage Multiple WordPress Sites With One Database and One Code Base. One of our developers wrote it in 2008, and it's been working well for me ever since.

The problem is that everything isn't controlled in one admin, which is very annoying. Especially as I continue to add new sites. I'm curious to know if you've had any issues with this setup. I'm also curious to know why WordPress hasn't implemented this, if it's technically possible, as you've just demonstrated.

Daniel: Here's a simple fix for sites not showing up under Super Admin->Sites when WP 3.0 is in separate domain mode.

Edit the file /wp-admin/ms-site.php, look for this query statement.

$query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";

Remove the WHERE clause. The new query should look like this.

$query = "SELECT * FROM {$wpdb->blogs} ";

Save it and give it try. I have 3 separate domain that I'm testing with and so far this has worked.

Thanks for writing your issues down, it has saved hours of work.

-Daniel

Mikito Takada: Daniel, thank you for that tip! Awesome!

dmartin: That was absolutelly perfect, thank you so much for the tutorial... Maybe I would add the correct mysql commands for newbies (I'm one of those, and it has taken a little time to guess the right syntax for the modifications), but everything runs perfectly well right now.

I've set up a test system with two blogs, and after that last modification (didn't show the two blogs after all the process in the Sites menu) everything is perfect.

I'm testing now the user registration, I'd like to add a Facebook Connect option and "build a community" (with or without FB) which could be useful in case users want to know each other. I've seen sites that do this, and I'll try to implement that on my blog network.

Great article, thank you so much!!

Ghufron: I've two difference domains, ghufron.com and postingan.com. Can I create multi-site with different domain? For example, I've installed WP 3.0.1 on ghufron.com and I want to create multi-site on it with postingan.com

Please reply via email :)

Thank you

Žiga Dolhar: Hey,

after following your instructions, I am able to log in to blogs on different domains. However, those blogs under different domains do not anymore show the "plugin" panel in administration. Also, linked to this, when I try to import contents into this new (on-a-different-domain) blog, the import plugin is not available (since it is a plugin).

DMartin: Daniel,

I've just repeated the process for an upgraded instalation of my blog network, and I've seen that that WHERE clause is not anymore at wp-admin/ms-admin.php if you are working with Wordpress 3.0.1.

Instead, you should edit wp-admin/ms-sites.php

Everything is the same for the rest of the comment.

Thank you so much for your post!

Mikito Takada: Ziga,

have a look at my post on fixing the problems with this setup, there should be solution: http://blog.mixu.net/2010/05/31/wordpress-3-0-multi-site-multi-domain-problems-with-solutions/

Daniel: DMartin, Great, I'm about to give 3.0.1 a go, thanks for the heads up.

-Daniel

Daniel: Has anyone had issues with 3.0.1 when editing sites? I'm getting "You do not have permission to access this page."

Editing worked on 3.0.0, now that I've upgraded it's broken.

I've found this line of code that may be the issue.

if($details->siteid != $wpdb->siteid) wpdie( ( 'You do not have permission to access this page.' ) );

site_id is the new domain, where siteid is the "root" domain or the main domain.

Any ideas?

Dan S.: Mikito,

Thanks for that post -- it solved most of the issues I've encountered.

The one problem that I haven’t been able to solve is a file size upload limit of 1mb. It’s neither respectful of the PHP.ini file size limits, nor any set in .htaccess

Any suggestions?

configure domain: This is an awesome resource.Thank you so much for putting it together in such a well organized and complete manner.I am going to use your site as a reference and hopefully learn more.I hope you publish more articles like this again shortly!

John: Where is $query = “SELECT * FROM {$wpdb->blogs} WHERE site_id = ‘{$wpdb->siteid}’ “;

on WP 3.1?

Thanks

Mikito Takada: ./wp-admin/ms-sites.php:16432: $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' ";

Vicente: /wp-admin/includes/class-wp-ms-sites-list-table.php

chandanks87: hi, For each new domain I need to do like this. Is there any plugin which substitute these all manual job.