Archive for the 'Geek Stuff' Category

04th Jan 2009

Consolidated WordPress

This blog hasn’t gotten much love since the 52 Churches project started.  I was really tempted to just delete it.  Quite frankly, keeping track of multiple installations of Word Press gets old.  Don’t get me wrong, I love WordPress.  We’ve been pretty happy with our hosting service from BlueHost, and the blog has been a good outlet for Jen, but maintaining 4 (now 6) of these monsters was getting old.

I needed a better solutions.  A little digging on-line came across an approach at This n’ That for modifying wp-config.php to adjust the prefix. It was close, but not quite what I wanted.  Basically, Mr. Kaplan was advocating adding some PHP code to the wp-config.php file that looked like:
// table prefix, for hosting multiple installations in the same db.
$table_prefix = ereg_replace('^(www\.)', '', $_SERVER['HTTP_HOST']);
$table_prefix = ereg_replace('\.', '', $table_prefix);
$table_prefix = $table_prefix . '_';

What this does is throw away the www and any periods (full stops for those of you inclined towards the Queen’s English) in the domain name and use the rest of it as the prefix. This is fine, but it’s suboptimal when it comes to long domain names. MySQL has a limit of 64 bytes for the table name, but that would have to be shared with the stripped down FQDN and the native WordPress table names. If you have a domain name like schoolsareforfish.garriber.org, you start pressing into that limit pretty quickly. Nonetheless it gave me the inspiration I needed for the solutions I was looking for. My thanks to Mr. Kaplan for his insight.

My other complaint is that it ended up making a multi-line change in a WordPress source file, albeit a configuration file. I wanted something substantially more self contained. My solution was this: create a php file in the wordpress root directory that does the prefix determination and have it return the desired prefix. For example, you could create a file called prefixgen.php. That file might look something like this:


< ?php
#figure out *which* site we're hitting
if(preg_match("/subsite1/", $_SERVER['HTTP_HOST'])) {
$prefix='ss1_';
}
elseif(preg_match("/subsite2/", $_SERVER['HTTP_HOST'])) {
$prefix='ss2_';
}
else {
$prefix='main_';
}
return $prefix;
? >

Note: I’ve put spaces between the ‘<’ and the ‘?’ to keep from confusing the computers

This does a pretty sloppy match. If the domain the user hits contains subsite1, it will map the prefix to ‘ss1_’. This is useful as it lets users go to www.subsite1.mysite.com, or direct to subsite1.mysite.com (assuming your DNS mappings and hosting provider are set up to support both). It does the same thing for subsite2. If nothing else it falls through to the main site (prefix ‘main_’). In this way, any DNS entry that resolves to your installation and gets to the right directory, but doesn’t map to a subsite, will go to your main site.

The update to wp-config.php becomes trivial. Change the prefix line to read:

$table_prefix = include 'prefixgen.php';

Presto! Clean and self contained. I’m a very happy camper. I now have a single directory with a single set of WordPress files serving all of our different sites. The sites are all stored in one database which makes for easier server side backups.  My “installations” at my hosting provider have become symbolic links to a single WordPress directory and, best of all, instead of having to manually update multiple WordPress installations, I just update one to upgrade.  Maybe I’ll let Jen keep this blog.  Maybe I’ll just take it over instead.  I could change the tag line to “Bits, Bytes, and Querries”

Posted in Geek Stuff, Zeteo | No Comments »

16th Oct 2007

Moving servers

garriber.org is moving off of our trusty Pentium M server and to an external hosting provider. As much as I love having my own local server, the ongoing energy consumption is a problem. The downside of this: fewer pictures. The upside: more likely to be on and available if you pop by to say hi.

Note:  as part of the this transition all of the old pictures are broken.  If you come across an old post that seems to imply a picture and has a lovely 4 digit number where one ought to be, engage your imagination and assume that something context appropriate used to be there.

Posted in Geek Stuff | No Comments »

07th May 2006

Integrating Gallery 2 into WordPress

The new garriber.org is being done using WordPress.  I recently added Gallery2.  Theoretically I should be able to reference pictures from it.  Enjoy the following from Hongkong.  It seems fitting for a geek post.
469

–Michael

Posted in Geek Stuff | No Comments »

07th May 2006

Wishes fulfilled

Jen has been pining for the return of her blog for some time. At long last I have migrated garriber.org to our own home server. Having done that, Jen can now blog until her heart is content, or her fingers have worn off.

Posted in Geek Stuff | No Comments »