Blog categories
Creating a Subversion Development Environment
Posted by: Elliot Haughin on the: 8 Nov 2006Requirements
Suprisingly, you don't need alot of things to get this working nicely:- Server to host the subversion repository
- Apache 2.x Installed
- 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:- Building Subversion on a Mac
- Subversion for Windows, Or Tortoise SVN for Windows
- On linux, you can usually just do: "apt-get install subversion" (Debian/Ubuntu) or "yum install subversion" (Fedora/Redhat) in console
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:
- Install subversion and mod_dav_svn
- Setup 2 subdomains dev. and svn.
- Configure svn.company.com to run a subversion repository with authentication
- Checked out a current version of the repository to dev.company.com
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-commitNow, 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
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...