<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rob Spencer &#187; Apache</title>
	<atom:link href="http://robspencer.net/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://robspencer.net</link>
	<description>Programming and Web Development</description>
	<lastBuildDate>Thu, 06 Aug 2009 02:05:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>One WordPress Installation For All Of Your Domains</title>
		<link>http://robspencer.net/one-wordpress-installation-for-all-of-your-domains/</link>
		<comments>http://robspencer.net/one-wordpress-installation-for-all-of-your-domains/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 02:01:58 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[virtual hosts]]></category>

		<guid isPermaLink="false">http://robspencer.net/?p=38</guid>
		<description><![CDATA[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 [...]]]></description>
			<content:encoded><![CDATA[<p>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&#8217;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. <span id="more-38"></span></p>
<p>For this to work, you will need to have a <a href="http://robspencer.net/recommends/servint/" target="_blank" rel="nofollow">VPS</a> or <a href="http://robspencer.net/recommends/the-planet/" target="_blank" rel="nofollow">dedicated server</a>. This won&#8217;t work on a shared hosting account as you will need to modify your httpd.conf</p>
<p>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.</p>
<pre name="code" class="php">
&lt;?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');
</pre>
<p>Then you want to find the line <code>$table_prefix = 'wp_';</code> and change it to <code>$table_prefix = $prefix;</code>. This will allow any domain pointing to this wordpress installation to use a different table prefix for each domain. </p>
<p>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:</p>
<pre name="code" class="php">
&lt;?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');
</pre>
<p>Then instead of changing <code>$table_prefix = 'wp_';</code>, you would leave that as is and change the line <code>define('DB_NAME', 'yourdbname');</code> to <code>define('DB_NAME', $dbname);</code> 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.</p>
<p>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.</p>
<pre name="code" class="c">
&lt;VirtualHost 123.45.67.89:80&gt;
    ServerName website1.com
    ServerAlias www.website1.com
    DocumentRoot /home/wordpress
&lt;/VirtualHost&gt;
</pre>
<p>You would then repeat this for each domain.</p>
<p>The easier and more preferred way is to simply point your server&#8217;s ip addresses to the wordpress installation. This way you can simply use your domain registrar&#8217;s DNS Servers and point the A records to your server. You would then set up your httpd.conf virtual hosts as follows.</p>
<pre name="code" class="c">
&lt;VirtualHost 123.45.67.89:80&gt;
    DocumentRoot /home/wordpress
    &lt;Directory "/home/wordpress"&gt;
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
    &lt;/Directory&gt;
&lt;/VirtualHost&gt;
</pre>
<p>Add this to the beginning of your virtual hosts section in the httpd.conf file, usually located in <code>/usr/local/apache/conf/</code> 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&#8217;t have a specific virtual host will be pointed to your wordpress installation.</p>
<p>That&#8217;s about all there is to it. Just restart apache (<code>/etc/init.d/httpd restart</code>) and you should be good to go. You can now point your A records at your domain registrar to one of your server&#8217;s ip addresses and when you visit the domain for the first time you will be asked to install wordpress.</p>
<p>PS &#8211; 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&#8217;t know what your doing then don&#8217;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.</p>
]]></content:encoded>
			<wfw:commentRss>http://robspencer.net/one-wordpress-installation-for-all-of-your-domains/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

