Page 1 of 1

Version Controlling VirutalHost Files

Posted: Wed Aug 15, 2007 4:24 am
by Ollie Saunders
I would like to be able to keep my virtual host files under version control and have them stored directly under the site to which they relate. Has anyone done anything similar to this before? My ultimate goal is to reduce the risk of failure/misconfiguration involved in deployment from development to production servers.

I guess I'm going to have to have a post-update hook that watches for any new virtual host files, sym-links them into the location where Apache can see them and gracefully restarts Apache. But looking at the subversion manual there doesn't actually appear to be such a thing as a post-update hook is that right? It's a little bizarre and annoying.

I'm using virtual hosts for all site specific configuration, I've disabled .htaccess and so some of them can be 50, 60 lines in length. A lot of the settings are server specific as well so I was thinking I could use PHP as a template language to have the final versions get dynamically generated by that post-update hook. For example:

Code: Select all

$data = array(
   'foo' => array(
       'htDocs' => '/web/sites/foo',
       'dbUser' => 'bob',
       'dbPass' => 'x',
   ),
   'bar' => array(
       'htDocs' => '/var/htdocs/foo',
       'dbUser' => 'jim',
       'dbPass' => 'x',
   )
);
$serverName = php_uname('n');
if (!isset($data[$serverName])) {
   trigger_error('Virtual Host settings not defined for this server,
falling back to default');
   $data = $data['foo'];
} else {
   $data = $data[$serverName];
}
?>
DocumentRoot <?php echo $htDocs ?>
<Directory <?php echo $htDocs ?>>
   Order Allow,Deny
   Allow from all
</Directory>

...
I've had some information from another source that suggested "The PEAR Installer Manifesto" for this purpose. In the initial description of that book it sounds like it was talking about using PEAR as a version control system but then there is a chapter on integrating it with subversion. I guess I need to get the book, I know very little about PEAR. It's certainly interesting but I'm not going to give up on subversion, I've only just got it all going.

Does anyone know anything about Ping?

Apparently there is also a database you can use that integrates directly with Apache but that doesn't really appeal because I don't want to introduce any more systems to my configuration and besides data in a database is harder to get to than just in the file system.

Whilst we're at it what other things do you do with hooks? I've seen recently that you can prevent merges and commits with failing unit tests, does anyone do that?