Saturday, March 20

Subversion , TortoiseSVN and configuring it with XAMPP.

What is subversion ?
As quoted by wikipedia
In software development, Subversion (SVN) (from February 2010 also named Apache Subversion ) is a version-control system initiated in 2000 by CollabNet Inc. Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation. Its goal is to be a mostly-compatible successor to the widely used Concurrent Versions System (CVS).
Well above is a formal definition of subversion. But why subversion?
OK, some days back even I did not know what exactly is subversion and why we need it. Read an article on it that said, subversion was extremely useful for keeping a track on and maintaining a project.

I have worked with some web development projects. Have designed some sites from scratch. It was not done in a day. So to keep a track of my everyday changes, either I would write it down on a book, or create a backup copy of the project and rename the folder with the date. For example Project_18thmarch. I know this is LAME but we had to have some kind of record for that. This is very very tedious, eats up lots of your storage, creates multiple copies of your project and also, does not serve the purpose. Instead of making it simple, this makes keeping a track on your project worse.

What subversion does for you?
Well this open source software, keeps a track of your project for you. Not only does it keep track of files, but also watches the file data for you. Any changes in any line of any file is being tracked for you. This software is widely used all over, and also, it helps many developers work on the same project at the same time. It was widely used by open source community for projects for example in projects such as Apache Software Foundation, Free Pascal, FreeBSD, GCC, Django, Ruby, Mono, SourceForge, ExtJS,, PHP and MediaWiki.

Before you read further, a point to note. 
I will be writing here about subversion as an individuals POV. Subversion is widely used when a team is concerned. But here, i have installed it on my local system so that i alone can keep track of it.

Requirements :
1) XAMPP (I am using XAMPP windows version 1.7.1)
(apache version : 2.2.11 ,  php version 5.2.9 , Mysql version : 5.1.33)
2) Subversion
3) TortoiseSVN

Now that I already had installed XAMPP on my windows machine and did not want to disturb its working, I had to search for some tutorials which would allow me to configure subversion with already installed XAMPP.

You can get the latest version of subversion from here. Since we are using Apache 2.2.x, we need subversion which is configurable to apache. A word of advice here , please make sure your subversion is compatible to apache. This will save a lot of time.
I used subversion version 1.6.5 stable i.e ( : Subversion Win32 binaries for Apache 2.2.x (2.2.11 or higher is required within the 2.2.x series))

TortoiseSVN : It is a subversion client for windows. It has a GUI and helps dealing with subversion repositeries. The latest TortoiseSVN version available is 1.6.7 and you can get it from here.

Procedure :
1) First step is to Turn off your apache , mysql services from your xampp control panel

2) Unzip subversion in your hard disk. My location was C:/Program Files/Subversion

3) Install tortoiseSVN. It is a simple to follow installer. My installation was in C:/Program Files/TortoiseSVN. Once you install it, you can see it in your context menu (Right click on desktop).

4) Now add the subversion bin directory to environment variable. Here is Microsoft’s definition to environment variable

Environment variables are strings that contain information such as drive, path, or file name. They control the behavior of various programs. For example, the TEMP environment variable specifies the location in which programs place temporary files.

Right click My computer -> properties -> Advance -> environment variable -> Double click on Path and then add this string. For me it is C:/Program Files/subversion/bin.

5) Next step is to include the mod files, into apache modules. Go to C:/Program Files/subversion/bin and copy the following two files.

6) Now Copy the following files from subversion bin directory i.e C:/Program Files/subversion/bin 
Paste the above files into apache bin directory i.e C:/xampp/apache/bin

7) Now you need to change the httpd.conf file from apache.
Go to C:/xampp/apache/conf and open httpd.conf in your editor. Search and Uncomment the following lines

LoadModule dav_svn_module modules/
LoadModule authz_svn_module modules/

8) Next is to add the location of subversion repositories in your httpd.conf file so that apache knows where to look for them
Add the following lines of code at the bottom in your httpd.conf file.
<location /svn>
   DAV svn
   SVNParentPath c:/svn
   AuthType Basic
   AuthName "All my repositories"
   AuthUserFile c:/svn/passwords
   Require valid-user
I got this configured from here. You can visit this article; it explains each line of code. I have created a directory called svn in C: drive so that I can keep track of multiple subversion repositories. For this I have used the svnParentPath directive.
We can provide a username and password so that only intended user can get to browse the repositories.
The AuthUserFile directive can be used to provide the password file. You can create this password file through apache’s htpasswd utility for managing the list of acceptable usernames and passwords, those to whom you wish to grant special access to your Subversion repository.
In this example I have created the password file in svn directory.

Go to command prompt (start -> Run -> cmd) and get down to your C: drive.
Browse in to your apache directory in command prompt.
C:/xampp/apache/bin>htpasswd.exe –c C:/svn/passwords admin and then hit enter. You will be prompted to enter a password. This password will be converted to md5 and saved along with your username.
 10) Now Turn On your xampp control panel. And start your apache and mysql services. Sometimes the apache service may not start. It happened to me many times. And the xampp control panel would not give any error. The best step here would be to start apache manually through your command prompt. Go to C:/xampp/apache/bin/apache. The figure below will give a better idea.

What I did was to shut down and restart my system. Also I had first installed a lower version of subversion i.e SVN 1.5.6 and I intended to using it with the latest version of TortoiseSVN 1.6.7. However a lot of google search and some questions over stackoverflow made me realize that I had to use proper versions of both the softwares.

Now create your project folder in svn directory. Name it "test". Now if you point your browser to http://localhost/svn/test then you will be asked for username and password. Enter the required fields and then you get the following error.

I haven’t done any research on this, but my guess is that since we do not have any repositories created yet , we get this error. So let us now create repositories.

What is a repository?
The repository stored information in the form of a file system tree – typical hierarchies of files and directories. Repository is kind of a file server, but what makes the subversion repository special is that it resembles every change ever written, and even changes to the directory tree itself, such as the addition, deletion and rearrangement of files and directives.
Our next step is to create a repository. Go to the test folder and right click on it. Select tortoise svn and then select create repository.

Now you can point your browser to http://localhost/svn/test
Enter the username and password.
It shows revision 0. This is the default revision, and since we do not have any files in the repository , it is empty.
Let us create our first project and import some files in the repository.

1) We create a test folder in our root folder. i.e in htdocs folder. Next we create a php file and enter some text in it. Now we need to import this project in our repository.

2) Now import this Project in your repository.Right Click on the project folder, i.e test in my case, then select Tortoise SVN and then select Import. After clicking on import you will have to select the repository directory. In my case it is file:///C:/svn/test
You can add a message to your import. Try to be descriptive in your message so that it helps in future.

After you click OK, the import will take place.
3) Now that I have created a repository, Next step is to start working on the project. For that we do a svn checkout. Svn checkout will help you get the latest working copy of your project from the repository. Go to your htdocs folder in C:/xampp/htdocs and right click. Click on SVN Checkout.

After SVN checkout is finished, it will show the revision number which is revision 1. And then you will have a working copy of your project.
The working copy has a green tick mark. Even the files inside the folder get a tick mark.

4) Now you can start working with your project. But first thing to note here is. Every time your work on your project, make sure you update the working copy. This is useful when there are many developers working on the same project simultaneously.
Right click on your working project, i.e Test folder and then SVN Update.

5) You can now start creating new files, or edit your old files. The new files added, edited will then be shown with a red image. This tell us that, these new files are added and yet to be committed in the repository.

6) After making changes you can then commit with SVN.

PS: I am no expert in SVN and in a pursuit to learn more about it. I had a very difficult time configuring SVN with XAMPP. The reason being.
a) I had installed a lower version of SVN and a higher version of Tortoise SVN. They were not compatible with each other. I learned about it, when I spent some time reading the documentation. So it is worth noting here, that whenever you install any software, check for its version and check for its compatibility.
b) On my machine XAMPP starts automatically on windows. I did not take much care about xampp, but when copying the mod files in module, it gave errors. So it is better to stop all the xampp services, configure your subversion and TortoiseSVN  and then restart your XAMPP.
c) Sometimes some changes do not affect immediately. It is a good practice to restart your system.

I hope this article helps anyone who wants to get started with subversion. This is a beginner lever tutorial. I have tried to avoid any mistakes, but if you find any, please point it out.

References and credits.

I had also posted a question on This is a very good site and you get a lot of help from people with similar interests in programming.

Be the first one to Comment!!!

  1. just three days... oh thanks mate... just four days back you tried installing subversion. If you haven't I would be going through exact same thing you must've... really appreciate yourself.

    Works awesome. Followed. Tested. Approved :) Works superb.

    Just wanted to know why are you using older versions still, e.g. XAMPP 1.7.1 instead of latest XAMPP 1.7.3 and Subversion 1.6.5 instead of 1.6.6???

    Thanks again.

  2. Oh one more thing,
    a post on how exactly is your developer environment is setup will be excellent.
    Just wanted to know how others are working in their environment.

    A short post on what installs/softwares you are using will do the trick as well..

    I am currently using: XAMPP 1.7.3 + Trac 0.11 + Subversion 1.5.6 + NetBeans 6.8 + Notepad++
    (anything else, is probably out of my mind, right now) :D

  3. HI, soul, appreciate your comment. I think i need to work on the software updates now. Yup will consider Your suggestion on developer environment. It sounds good. and if all share their developing environment then we will get to a learn a lot.

    well am right now using e-text editor. It is similar to text mate for mac. And even notepad++ is the best free editor which i normally use.

  4. EXCELLENT the guide works by itself !!! after a whole day looking for explanation, this is the only guide that explain everything from a-z hahaha.

    Just one thing you could correct the images? There are plenty of them that are not visible

    Thanks awesome work

  5. Thanks Daniel. Thanks for your suggestion, am working on it.

  6. Hi,

    Excellent post I have tried it and its been done. but have only one if you could help me out?

    I can't access the repositories there is an authentication error i did make new users but all in vain.

    I can access the repository only by the local server file:/// but can't access it neither from explorer nor from TSVN from client end (other computers)

    httpd.conf settings are:

    DAV svn
    SVNParentPath c:/svn
    AuthType Basic
    AuthName "All my repositories"
    AuthUserFile c:/svn/passwords
    Require valid-user

  7. Hello Moazzam,

    SVN works with 3 protocols (File, HTTP and SVN):

    1. File: can be accessed from everywhere while the computers has mapped the shared folder.
    2. HTTP: is the one that is used by apache, I know that Idrish guide is always talking about file:/// but maybe wanted to mean HTTP
    3. SVN: is the protocol of subversion is faster and more stable than the other 2 protocols, but I couldn't configure with users and it is more complicated than option 2.

    Another thing to add is that 1 doesn't need a server only shared folder, 2 needs apache running and being an intermidiate and 3 needs svnserve running (the last one is the recommended one, not "difficult")

    Idrish do you know how to configure apache to use auth file and how auth file works?

    Another question when we used this "" we indicate Apache to redirect internally to our folder where all the repositories will be, but i want to be already inside the repository like c:/myrepository/myProject/trunk, is that possible? How? Because i tried it but it gives me the error like repository doesn't exist so i have to enter /svn/MyRepository/MyProject/trunk (All this because I would like to make it transparent to the MyRepository users)

  8. Hi Daniel,
    Indeed you have a good knowledge about SVN. My tutorial was on a introductory level and a beginer's point of view. I myself had a difficult time configuring svn with apache, so put up this guide to help all those in a situation like me. Anyways coming back to your question, configuring apache with svn, only means that we can check our project and keep a track on the repo through a web-browser, visiting http://localhost/svn.

  9. Hi Idrish,
    I was investigating a little bit through the SVN-BOOK.pdf about restriction acces per directory with apache and came accross this

    SVNParentPath: used to specify where all your repositories will be (so that's why you have to specify where to go /svn/repo1 or /svn/repo2)

    SVNPath: used to specify one single repository (if you enter in /svn apache is expecting to return the root of the repository)

    Now the question is why do we have both Path directives? According to the book says, if we are planning to have a server with multiple subversion repositories then SVNParentPath should be the best option in order to avoid stopping the apache everytime you wish to add a new repository.

    This comment do not solve the fact that I want a single address which get me into the trunk for example but certainly is a forward step to clarify this.

    In other hand Idrish do not despise your guide, it helped me alot and gave me a start point to attack my problem, thanks to your guide i'm able to access to my repositories thought internet.

    I'm trying just to learn and in this way help others to get a more complex and secure server. If you want you can fill your guide with more information.

    Also Idrish, I invite you to get the book and go to page 163 (page 186 in the whole document i guess) and get some ideas to complete the guide, I can help you through my understanding. If you need more help or just get in contact with me feel free to contact me (i will facilitate my email addres in the blogger profile)

  10. Hi daniel,

    Thanks for pointing me to the guide. It would be great if we could share our knowledge with other's so that they do not have any issues when configuring svn with apache. Am downloading the book as i type and looking forward to read the book.

    Dear Daniel, the main idea of using SVNParentPath is to get all your repositories. Which is what you suggest. Also, if you need to get a particular repository as you ask, i think tortoiseSVN should solve your issue.

    Am still confused as to why you need to access a particular repository?? Are you creating users and want only some of them to have the authority to get the repository??

    The problem right now am facing is the setting up of proper environment. As you may have noticed, my environment basically has a local server viz xampp and am the only user playing with the repository.

    However your curiosity has made me go beyond this tutorial, and think out of the box. Thanks.

  11. I just can't get Apache started :( since adding the lines in the conf file
    I'm using svn 1.4.6 and tortoise 1.6.9

  12. An internal error ocurred after a tried to acess the localhost/svn/test folder. It happened right before i entered login and password. Now it wont ask for login anymore, just the error occurs...
    what could it be?

  13. well, got it working!

    i had to specify in the apache/conf file the path for the password file like


  14. Thanks! Went through everything without any major problem!