by Frost
Introduction
The past few days I have been digging and diving and reading through many different tutorials about setting up SVN (or Subversion) through Apache2 on Debian based Linux Distro's. After many trials and errors and taking down my webserver a few times I finally was able to get a full on SVN Server for my main website up and running with Authentication over SSL, and here is my tale.
The Line of Thinking
I have always wanted an SVN server for my main web server but never really had the time or motivation to figure out how to do SVN through command line (SSH) and on a Debian Linux Distro. Well the past couple days I have spent countless hours working on my main Xubuntu install getting SVN figured out and working. Then porting that over to my Server which has Debian Etch installed on it. How I wanted my SVN repository setup was what made sense to me for a web server. I stuck to the basic Tree with "trunk" and "branch" but decided to omit the "tags" since it is a website I am "versioning". Here is the tree structure:
| ___ branch
| ___ www
| ___ trunk
| ___ www
This structure suited my needs perfectly, as I wanted my other developer (it is only me and one other person) to be able to setup a webserver locally with branch then once the code is working under branch copy it over to trunk. Anything in trunk could at anytime be copied to webroot via a shell script. So I have stressed many times to only copy / commit working projects / files to trunk. Since this makes sense in my mind, it may not in yours, so do what you feel is best, I just found that structure to work for my needs.
Preparing The Server
Whether you are going to be setting up SVN on your local server just for your self to keep track of projects or on your remote server there are some steps to take to setup the server, with the first one being making sure you have the packages installed that need to be installed. If you are using Debian, the aptitude package manager. Here are a list of packages that are needed (Note I am assuming you are working under Apache2):
subversion
libapache2-svn
So a simple command (seen below) can make sure you have these packages installed:
1 | sudo apt-get install subversion libapache2-svn |
Once that has been done, we need to make sure that DAV and SSL (if SSL is wanted) are enabled by doing some simple commands:
1 2 | sudo a2enmod dav sudo a2enmod ssl |
If for whatever reason you need to disable a module, the opposite to a2enmod is a2dismod (dis for disable). This is much easier then manually creating the symbolic links, and I would suggest you to use it.
Now that we have our webserver prepared (sort of) to at least handle Subversion Repositories the DAV mod and SSL connections, let's get to creating the subversion repository.
Creating the Subversion Repository
The subversion creation is really straight forward. I put my repositories under /var/svn/project_name, this is just a preference, feel free to choose where you want to put the repository, just remember the location as we will need it when we get to the VHosts file later on.
Before we get to far into the subversion, I love to create a template directory structure to do for the initial import, so here is a bash script, using a similar path to the one above to setup the structure I have outlined in this script:
1 2 3 4 5 | cd /var mkdir svn cd svn mkdir -p template/branch/www mkdir -p template/trunk/www |
Using the directory I stated above, here are the commands I would use to create the initial repository:
1 2 3 4 5 6 | cd /var/svn mkdir project_name svnadmin create project_name chown -R www-data:www-data project_name chmod -R g+rws project_name svn import templates/ file:///var/svn/project_name/ -m "Initial import for structure." |
Those commands are pretty straight forward. We need to change the owner (chown) to be www-data so Apache can effectively create / delete items to and from the repository. We also need to change the mode (chmod) to g+rws which essentially sets that any user part of the group www-data has read / write / and to set the user / group id upon execution. Viola we should have a fully working Subversion Repository (well almost fully working).
