Design Ontap

If you're looking for UK based web development fulfilment, Design Ontap are here to help. Call us now: 0845 644 7782

Blog categories

  1. Technology (5)
  2. General web (1)
  3. Industry (3)
  4. Business (1)
  5. PHP (1)

Browse all posts

Creating a Subversion Development Environment

Posted by: Elliot Haughin on the: 8 Nov 2006

Subversion is a version control system that is a compelling replacement for CVS in the open source community.

It allows developers to make changes to files, and 'Commit' them, in a way that many people can work on the same bits of code without overwriting each others changes and having them lost forever. This tutorial will help you set up the development environment of your dreams!

WARNING: THIS GUIDE IS VERY TECHNICAL... THIS IS NOT RECOMMENDED UNLESS YOU HAVE EXPERIENCE IN MAINTAINING A LINUX SERVER

Requirements

Suprisingly, you don't need alot of things to get this working nicely:
  1. Server to host the subversion repository
    1. Apache 2.x Installed
  2. Client machine (usually your PC/Mac which you develop on)

Client Machine

Let's get started on setting up your local client machine. You'll need to install subversion on it. Here's some basic guides to doing so:
  1. Building Subversion on a Mac
  2. Subversion for Windows, Or Tortoise SVN for Windows
  3. On linux, you can usually just do: "apt-get install subversion" (Debian/Ubuntu) or "yum install subversion" (Fedora/Redhat) in console
OK, so now we have your local machine set up with subversion... just as a client, not a server. This means that you'll be able to 'checkout' svn repositories, make changes, and commit them to the server. Now we just have to get the server set up.

Server

First of all, let me explain the structure of how things will work.

Let's assume we have a domain: company.com
We're going to create two subdomains:
svn.company.com
dev.company.com

Now, svn.company.com will house the subversion repository, the database of files and changes with which we will commit our changes.
Then, dev.company.com will be a 'current' copy of the latest version of svn.company.com, but it will be accessable via the web, so you can run your application/site for testing.

But, there's a little bit of work to do to make sure this all comes off according to plan.
Mainly, we need to 'refresh' the contents of dev.company.com everytime a change is made and commited to svn.company.com.

Let's get cracking then.
SSH into your server.

Firstly, we install some software on the server.

yum install subversion

This command will painlessly install the subversion package.

yum install mod_dav_svn

This command will install the apache 2 svn module.

svn --version

Now, if you don't get an error saying 'Unknown command: svn', you're doing fine :) This just checks subversion is correctly installed.

mkdir /var/www/svnrepo

This command creates the empty directory which will house our subversion repository.

svnaddmin create /var/www/svnrepo

This command turns the directory into a working subversion repository.

chmod -R 777 /var/www/svnrepo

Changing the permision of svnrepo folder to allow Apache/Subversion to have read/write rights.

Configuring Apache

Open the file /etc/httpd/conf/httpd.conf

nano /etc/httpd/conf/httpd.conf

Search for mod_dav_svn.so in the Modules section.
If you don?t find this line in httpd.conf, then check the folder /etc/httpd/conf.d/ for other .conf files.
I have a subversion.conf file here which is included in the main /etc/httpd/conf/httpd.conf at initialization time.

In this subversion.conf file, there are these 2 lines to make sure that Apache loads the SVN modules:

#File: /etc/httpd/conf.d/subversion.conf
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

As long as we have these lines, we know that apache's subversion module is installed correctly. Let's setup our subdomains now.

(WARNING: MANY CONTROL PANELS PROVIDE A METHOD FOR ADDING A SUBDOMAIN! IF YOU ARE USING A CONTROL PANEL, ADD YOUR SUBDOMAINS THROUGH IT!)

If the above does not apply to you:

nano /etc/httpd/conf/httpd.conf

Scrolling through the file, you should see at least 1 or 2 zones. After these, add:



DocumentRoot /var/www/html/dev
ServerName svn.company.com
DAV svn
SVNPath /var/www/svnrepo
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/httpd/svn.auth
Require valid-user

DocumentRoot /var/www/html/dev
ServerName dev.company.com
AllowOverride All

What we've done here is said that svn.company.com is to be handled by subversion, with some basic authentication. And, dev.company.com will just run through apache as usual.

Let's create the empty directory for dev.company.com:

mkdir /var/www/html/dev

And make sure apache has the rights it needs: Now, let's checkout the current (empty) repository into dev.company.com:

cd /var/www/html/dev
svn co file:///var/www/svnrepo/ .

And, let's give apache rights on this directory...

chown -R apache:apache /var/www/html/dev

So far, so good... now let's create the file that contains our authentication information.

htpasswd -c /etc/httpd/svn.auth username

(replacing username for your own username)
Enter your desired password, and press enter, (it asks twice).

Now, it's time to restart apache.

service httpd restart

Now, things are going pretty well.... We've managed to:

  1. Install subversion and mod_dav_svn
  2. Setup 2 subdomains dev. and svn.
  3. Configure svn.company.com to run a subversion repository with authentication
  4. Checked out a current version of the repository to dev.company.com
Now al that remains to be done, is to have it so that every time the svn repository is changes (through a 'commit' command), dev.company.com receives a fresh copy of the 'latest' files.

Enter 'hooks'.

'Hooks' are scripts that a subversion repository will automatically run on certain actions.

We need to set up a post-commit hook, which will run after a commit has been made to the repo.
Hooks are located in /path/to/repo/hooks In our case: /var/www/svnrepo/hooks

Let's create a new file:

nano /var/www/svnrepo/hooks/post-commit

This file will be blank, but we're going to add the following 2 lines:

#!/bin/bash
/usr/bin/svn update /var/www/html/dev
> /var/www/svnrepo/hooks/post-commit-log

Quite simply the command says:
Every time a commit has been made, 'update' dev.company.com, and save the log to post-commit-log.

Save the file, and set some permissions on it, this needs to be executable.

chmod 777 /var/www/svnrepo/hooks/post-commit
Now, lastly, let's restart apache again.
service httpd restart

And there we go.

Now, every time a 'commit' is made on svn.company.com, the latest files can be run through apache at dev.company.com

Easy huh?
(Now you can see why linux guru's deserve to by paid more! ;) )

Elliot

View comments (0) | View trackbacks (0) | Permalink | Trackback

There are no comments for this post

Latest News

Site Foundry reaches its first birthday // 20 Sep 2007

After two full point versions and a number of upgrades under the...

1

Web development with a nicely designed exterior