One Wordpress Installation For All Of Your Domains
If you have a lot of wordpress sites like myself, you are probably annoyed with having to update each and every install on all of your domains. Not to mention that having so many installs takes up a lot of unnecessary hard drive space with all of the duplicate files for wordpress and all of the plugins we seem to use on every blog install. Wouldn’t it be nice to just upgrade wordpress and your plugins one time and have it reflect on all your domains? Well you may be surprised by how easy this actually is to accomplish.
For this to work, you will need to have a VPS or dedicated server. This won’t work on a shared hosting account as you will need to modify your httpd.conf
The first thing we will need to do is edit our wp-config.php file. We will put all of the domains that will be pointed to this installation in an array. We then check which domain the user is visiting and change our table prefix to reflect this. Add the following code to the top of your wp-config.php file.
<?php
$domains = array(
'website1.com' => 'wp1_',
'website2.com' => 'wp2_',
'website3.com' => 'wp3_'
//Add more as necessary
);
$domain = $_SERVER['HTTP_HOST'];
if(array_key_exists($domain, $domains))
$prefix = $domains[$domain];
else
die('Blog Doesn\'t Exist');
Then you want to find the line $table_prefix = 'wp_'; and change it to $table_prefix = $prefix;. This will allow any domain pointing to this wordpress installation to use a different table prefix for each domain.
If you prefer to setup separate databases for each domain then instead of using a table prefix as the array values, you could use the database name. That would look something like this:
<?php
$domains = array(
'website1.com' => 'dbname1',
'website2.com' => 'dbname2',
'website3.com' => 'dbname3'
//Add more as necessary
);
$domain = $_SERVER['HTTP_HOST'];
if(array_key_exists($domain, $domains))
$dbname = $domains[$domain];
else
die('Blog Doesn\'t Exist');
Then instead of changing $table_prefix = 'wp_';, you would leave that as is and change the line define('DB_NAME', 'yourdbname'); to define('DB_NAME', $dbname); and this will use completely separate databases for each domain. However, the problem with this is that you would have to create each database separately. If you do it this way then be sure to use the same user and password for each database to keep it simple.
The next step for this to work is to modify your httpd.conf. There are 2 ways you can do this. The longer and more complicated way is to create a virtual host for each domain and point each of them to your single wordpress installation. So if you have your wordpress files in /home/wordpress/ then you would create your virtal hosts like the following.
<VirtualHost 123.45.67.89:80>
ServerName website1.com
ServerAlias www.website1.com
DocumentRoot /home/wordpress
</VirtualHost>
You would then repeat this for each domain.
The easier and more preferred way is to simply point your server’s ip addresses to the wordpress installation. This way you can simply use your domain registrar’s DNS Servers and point the A records to your server. You would then set up your httpd.conf virtual hosts as follows.
<VirtualHost 123.45.67.89:80>
DocumentRoot /home/wordpress
<Directory "/home/wordpress">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>
</VirtualHost>
Add this to the beginning of your virtual hosts section in the httpd.conf file, usually located in /usr/local/apache/conf/ on most server configurations. If you are using more than 1 ip address on your server then add an additional virtual host entry for each ip address. If you have other domains on your server with a proper virtual host entry then those domains will still work and point to the correct location. All domains that don’t have a specific virtual host will be pointed to your wordpress installation.
That’s about all there is to it. Just restart apache (/etc/init.d/httpd restart) and you should be good to go. You can now point your A records at your domain registrar to one of your server’s ip addresses and when you visit the domain for the first time you will be asked to install wordpress.
PS – As with everything I post on this site, I take no responsibility if you screw up your server. Use this at your own risk and if you don’t know what your doing then don’t do it. If you are uncomfortable doing this yourself and you would like me to do it for you then contact me and I can do it for a respectable fee.

September 30th, 2009 at 11:49 pm
How might this affect performance if there are hundreds or over a thousand domains?
September 30th, 2009 at 11:50 pm
Also, any affect on having different plugins and themes for each domain?
October 1st, 2009 at 9:32 pm
Performance really depends on your server specs but it would be much better than running hundreds or thousands of separate wordpress installations on those domains.
Your plugins for all your domains exist in a single folder and you can activate different plugins and themes for each domain independently.
November 1st, 2009 at 3:31 am
Hi there. Thanks for the tips. I work with Aaron, who commented earlier. We used some of the techniques you described, and it has saved us many GB of disk space.
However, with just 200 domains running, our server is getting HAMMERED!
Do you have any suggestions on this? I know about page caching, and that is a solution I am working on, but we have many thousands of posts per domain and that is time consuming.
One thing I noticed is that requests for wp-cron.php gets spawned a LOT. That can’t be good for performance. Is there some to disable Wordpress’ internal cron scheduler and instead invoke cron processing manually from the command line?