Hosting Client Sites on a WordPress Network
Regular updates keep WordPress secure and expand the feature set, ensuring the platform meets both the developer’s and their client’s needs.
The flipside of regular updates is the maintenance of WordPress installs. Once you start maintaining more than a few installs for your clients, keeping both plugins and WordPress up to date can become a bit repetitive.
Setting up a WordPress Network, using the multisite feature, reduces maintenance time. Upgrading all your sites becomes almost as easy as upgrading it for one.
Setup hosting to allow wildcard sub-domains
I’ve found setting up a WordPress network in sub-domain mode – site1.example.com
, site2.example.com
– works slightly better than it does in sub-directory mode.
Sub-domain mode requires you set up wildcard aliases for your web and DNS servers. Setting up a wildcard alias in Apache requires a single line be added directly below the appropriate ServerName command:
SeverAlias *.example.com
On your DNS server, add a wildcard sub-domain pointing to your IP address:
*.example.com 10.10.10.10
The WordPress Codex provides further information on setting up wildcard domains for various control panels.
Install WordPress and setup Network
You need to setup a WordPress network from a fresh install of WordPress. As a reader of Digging into WordPress, you can probably do this in your sleep.
Unlike a standard WordPress install, a WordPress Network must be installed in the root directory of a web server. I purchase domains for this purpose but you can use a sub-domain.
Once your wp-config.php
file has been generated, add this line to the file:
define('WP_ALLOW_MULTISITE', true);
You then need to visit WP Admin ▸ Tools ▸ Network where the instructions to create a network are easily followed. The Create a Network page in the WordPress Codex is also helpful.
You’ll be ask to make changes to the .htaccess
and wp-config.php
files and create the directory blogs.dir
in wp-content
.
Decide on limitations
Before setting up clients on a WordPress site, you need to decide what you’ll permit them and their visitors to do. The settings you choose here affect everyone from site administrators down.
The settings to consider are (the settings I use are in brackets):
- Can site administrators create new users? (No)
- Which media upload buttons appear above the visual editor? (All)
- How much disk space does each site have for uploads? (Unlimited)
- What types of files can be uploaded? (Default listing)
- Maximum upload size of an individual file? (20000 kb)
- Is the plugins menu enabled for sites? (No)
I strongly advise you to keep the plugins menu disabled too. Your client is paying you to maintain WordPress because they lack the technical expertise; you don’t want them to enable WordPress Reset and delete everyone’s database.
Registration settings for the network need to be configured to. As this is for hosting your client’s sites, you’ll want to disable registration of new sites. You can choose to disable registrations entirely or allow user accounts to be registered, totally your call.
To keep track of who is using the system, I disable registrations entirely. Site owners contact me when they need to add another user. Disabling registrations also prohibits requiring visitors to register before they can comment.
Once you’ve considered the limitations you want to apply to your clients, set them up at WP Admin ▸ Super Admin ▸ Options.
Adding clients to a WordPress Network
You can add users to the network at WP Admin ▸ Super Admin ▸ Users. I use a standard format for usernames to make searching easier.
With users added, you can now add their sites through WP Admin ▸ Super Admin ▸ Sites. Once their site is added you need to:
- Edit the site (hover over the site in the list and click edit)
- Enable the theme/s for the site
- Add users with appropriate permissions to the site
Install Domain Mapping Plugin
Your client’s sites will use their own domain, rather than a sub-domain of the WordPress Network. This requires Donncha O Caoimh’s WordPress MU Domain Mapping plugin.
Unzip the plugin on your local machine, upload domain_mapping.php
to the directory /wp-content/mu-plugins
(create it if it doesn’t exist) and upload sunrise.php
to /wp-content/
. In your wp-config.php
file add the line:
define( 'SUNRISE', 'on' );
Go to WP Admin ▸ Super Admin ▸ Domain Mapping and set your server’s IP address or its domain name in the CNAME entry. I always enable permanent redirect and usually enable user domain mapping page. If using a caching plugin (see below), I disable redirect administration pages.
You can then add domains to your client’s sites by visiting WP (Client Site) Admin ▸ Tools ▸ Domain mapping.
Otto has written up a great guide to using the domain mapping plugin.
Selecting plugins
A poorly coded or insecure plugin can cause enough problems on a standalone WordPress install. Because a WordPress Network uses the same files and database across multiple sites, the problems are compounded.
Choosing plugins for a WordPress Network requires a glass half empty approach. The feature list of a plugin will tell you what it adds to your site, the code and support forums tell you what it takes away.
A good approach to take is to stick to plugins and plugin authors that are well-respected within the WordPress community. Plugins used on WordPress.com are a good starting point, as are plugins by Yoast, Donncha, and Automattic.
Big name or not, review the plugin’s code before installing it on your WordPress Network. Look for forms using nonces, wide use of the WordPress APIs, escaped database queries, among other things.
Other considerations
Hosting more sites on your server uses more resources so you should find ways to lighten the load.
The first plugin I install, (this goes for standalone sites too) is Jason Penny’s Use Google Libraries, which uses Google’s servers for hosting available JavaScript libraries. You must load JavaScript the WordPress way for this to have an affect.
If you’re creating bespoke themes for your clients, you probably have a standard starting point. If you’re not already doing so, you should use parent & child themes so you can fix bugs in your starting point and the changes instantly propagate to all the sites you host.
A parent theme will also allow you to share resources across multiple sites. If you use a base JavaScript or CSS file, always reference it from the same URL.
If you want to lower resource use further, install a caching plugin. I use W3 Total Cache on my server. It’s not easy to configure but when I did so, I saw an immediate drop in resource use and, more importantly, Pingdom reported a five-fold drop in response times.
Total Cache makes significant changes to the .htaccess
file so exactly the same settings need to be used for all sites on your network.
Security, security, security
As I said earlier, a WordPress network shares files and the database across multiple sites. Any security issues a plugin, or theme, introduces are compounded as a result.
I can’t emphasise enough the importance of putting security first.
Special guest post by Peter Wilson
43 responses
-
I thought about this before – how easy is it to export a site if the client wants/needs their own server?
-
You would just use the export function in WordPress to export your pages, posts, comments, etc. You would then need to copy down the theme directoy, blogs.dir directory for that site (for uploaded content), and plugins that are required for that site.
You could also export the database tables for that site and then rename them later for a standalone WP installation.
-
-
Good idea, Peter. I am moving my sites to multisite soon. Currently I use multisite only on a dev server. Don’t have the guts to use the same approach for my clients, yet. ;-) But I love this approach to reduce the stress on the server.
-
I find it helps if I explain to people what they are really doing when setting up a network is making their own version of WordPress.com for their clients.
moving sites on and off the network has the same steps.
-
The downside to disabling “redirect administration pages” with the domain mapping plugin is that then you will still need to log into each site. The upside is that the end user/administrator will see their full domain (not subdomain.yourdomain.com) for the admin side.
I’ve decided to leave “redirect administration pages” enabled so I do not need to keep logging into my other sites. The client doesn’t seem to care or even notice that the admin URL says subdomain.yourdomain.com).
-
Thank you! I had wanted to do this before, but got stuck at not wanting everything to be on the same domain. Did not know there was this domain-mapping plugin.
-
Sub-domain mode requires you set up wildcard aliases for your web and DNS servers.
Is this something that can be done on most standard web hosts, such as Bluehost? If not, what kind of hosting account do I need?
I can get around WP but the deeper system stuff has me confused.
-
I believe most shared hosting plans do not allow you to setup wildcard aliases. However, you can always ask the host if they will change it for you.
If you are going to be using multsite with a lot of sites, then you should really consider going to VPS hosting.
-
Bluehost does not support wildcard subdomains, tho some users have found it is enabled. But they don’t *support* it so it could go at any time.
GoDaddy (ugh) requires you to upgrade to a static IP. Dreamhost I think does. 1and1 does not. Hostgator and Site5 are fine.
Basically, some shared hosts don’t because it completely circumvents any caps they give you on subdomains, and it can be more resource intensive, plus may violate their TOS (if it disallows giving away free web space and you have open signups).
Any VPS host usually has wildcard subdomains enabled, like Wiredtree.
You can also use the subfolder option, but that is disabled if you blog is more than 30 days old because it stuff a /blog/ in the main site’s Permalink structure to prevent collisions between page names and site names.
-
-
Great post!
We just launched our version of this. Couldn’t agree more about lightening the load on the server and security. We installed two plugins to help in those regards. Amazon S3, because some of the sites on the network are image heavy. And Login Lock Down for greater security.
-
I have a couple of these WordPress Networks setup and it works perfectly. Not sure about Donncha’s plugin though, but the one from @wpmuguru allows you to have a Network with subfolder installations. At least, that’s what I am using on my installations.
-
Would building a network this way allow users to have control of their own Themes or would they have to only use shared themes on the network?
Thanks,
AC-
Yes, you can assign only certain themes to each site. Instead of using network themes, I only assign the theme(s) on a per site basis. That way one site cannot see a custom theme for another site.
-
-
Re. the 11-Feb post:
This (below) makes no grammatical sense. Did you forget a few words or some punctuation?
“…people feel more comfortable hacking PHP did and still to this day.”
-
I was able to create sub-directories before installing the domain mapping plugin.
Once it’s installed, I could map unique domain names to those directories, BUT I couldn’t create any more new directories.
Does anyone know why?
-
Because I’ve always used sub-domains, I can’t verify this problem. If anyone has had similar problem, please drop in a reply to Suze’s comment.
-
-
I am using 1and1 for hosting and they don’t allow wildcard sub-domains. Can I still do this using sub-folders? If so is there anything I need to change while setting it up? Thanks!
-
On the create a network page, you just need to select sub-directory mode instead of sub-domain mode. I’ve found a couple of WordPress idiosyncrasies in sub-directory mode which is why I use sub-domain mode.
Above, @Suze reports additional problems when using sub-directories, I’ve not seen these due to the way I use WordPress.
-
Alright, thank you! I am actually installing that plugin as we speak. I will let you know if anything goes wrong.
-
-
Same here – I’ve had experience working with 1&1, what you can do is actually set up sub-domain names at admin.1and1.com before you do the same thing again in WP. Cumbersome, I know, but that’s how it works with them.
Another option is to switch to a different hosting company (which I’m seriously thinking of doing).
This makes me wonder if my sub-directory issue has something to do with 1&1’s set-up or the plugin is just a bit buggy?
-
I think it has to do with 1and1 since other hosting providers don’t have that issue. I called them and they told me they do not allow wildcard sub-domains. I am thinking about switching providers as well to a more WordPress-friendly one. Media Template looks nice but seems way too expensive.
-
-
-
Is a potential downside to this method that you might have a couple sites with themes that use deprecated functions or older plugins and they break upon update? (Or possibly some other reason they break on update)?
Probably an ignorant question, but can you specify that one or two of your sites stay on the older version temporarily until they can be made compatible?
-
It is a possibility that would have implications for the entire network. However, choosing frequently updated plugins by reputable authors will mitigate this problem.
I’ve only found one plugin that was problematic on a Network – a membership/permissions plugin – although upgrading hasn’t been a problem.
At Soupgiant, we use separate installs for our staging server and our live server. Performing upgrades on the staging server first allows a dummy run without the risk of breaking live sites.
-
Which membership/permissions plugin?
I’m using User Access Manager on one site that I haven’t moved into our multisite yet.
Good idea about having a staging server!
-
Snap! That’s the one I had problems with.
I didn’t spend long attempting to get it working on a WP Network as the client will be hosting the site themselves once the site goes live.
That’s to say, it could have been me and not the plugin.
-
-
-
-
Thank you for this tutorial. I made a mistake when installing the network, I selected subdirectory instead of subdomain. Is there a way to change this?
-
I don’t think you can switch from sub-directory to sub-domain mode after setup. If another reader knows for sure, it’d be great if they could add this a reply to Leo’s comment.
I’d love to be wrong on this. :)
-
-
What if the client has their blog located in example.com/blog/? What would I do then?
-
I’ll presume that the rest of example.com is a static, non-WordPress site.
You’d need to move /blog to a sub-domain – blog.example.com, for example – and use a redirect visitors to the new address using an .htaccess redirect.
In the .htaccess file for example.com, you’d add:
# send visitors to a subdomain
RewriteEngine on
RewriteBase /
RewriteRule ^blog/(.*) http://blog.example.com/$1 [R=301,L]
-
There is no other way? Thank you for your help!
-
I’m afraid not.
If you’re worried about loosing your Google ranking for the blog, the
[R=301
instructs search engines to treat links to the old URLs as links to the new URLS.
-
-
-
-
Interesting and useful summary, thanks.
You say sub-domain works better than sub-directories, and there are a few wordpress idiosyncrasies that lead you to prefer sub-domains – could you elaborate on these points please? how do sub-domains work better and what are the potential issues of using sub-directories instead?
Cheers.
-
It’s a couple of very minor things that I’ve noticed, small enough that I’d ignore them if in a tight spot.
The most frequent problem isn’t a core problem but happens often enough to become annoying. It’s plugins that will always submit to example.com/wp-admin/ when they should be submitting to example.com/site/wp-admin/
The second problem I’ve found is that automatically generated return urls are sometimes incorrect. For example a login form inserted on example.com/site1/permalink/ will be returned to example.com/site1/site1/permalink/. I haven’t had the chance to see if this has been fixed in 3.1 or write a patch for it if it hasn’t.
As I said, they’re such minor problems that I’d ignore/work around them in if forced too. Neither of them occur in sub-domain mode, so the easy option is to just use that.
Pete
-
-
What do you do if you want to use plugins like “WP-DBManager” to back up your WordPress site? Do I just use it on one “site” or all of them?
-
You just activate and run it on your main site. Just make sure you include all tables.
-
Okay, thank you.
-
-
-
Very good article! thank you to the author for it! In it interesting and useful information it is possible often times re-read it! I will advise to read it all friends. It will be very useful at writing of the article. Very much thankful you.
-
Read this post and made myself a cup of tea I’m a happy women already, whats in store for the rest of the day =)