Monday, February 22, 2010

Setup a http based SVN repository with TortoiseSVN and Apache http server

It is very useful to setup a http based SVN repository on your local machine just for daily check in and out of source code. I am pretty sure there are plenty of materials over the web that explain how to do it for different combinations. Here is the one which I went through and it works pretty good for me.
1. Install and configure TortoiseSVN
2. Install Apache HTTP Server
    • Download Apache HTTP Server from its' website at http://httpd.apache.org/download.cgi#apache22, and the version I’m using is 2.2.14 (either the one with or without ssl); try avoid using 1.x or 3.x which either doesn’t work well or hasn’t been tried by many people. So apache 2.2 is the best pick for now;
    • Install Apache http server by following the wizards;
    • Change the Apache HTTP Server listening port if necessary in conf.
    • After installation, just test it by launching http://localhost:port/ in browser and you should see a “It works!” page; (you can also monitor the apache http service in Apache Service Monitor)
3. Install Subversion
    • Download the latest version of the Subversion Win32 binaries for Apache. Be sure to get the right version to integrate with your version of Apache, otherwise you will get an obscure error message when you try to restart. If you have Apache 2.2.x go to http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100;
    • !!!DON'T!!! use the msi version of subversion (it doesn't work somehow), instead use the zip version; (after unzip the subversion folder to your local disk, you also need to add the bin path to 'path' system environment variable)
    • Using the windows explorer, go to the installation directory of Subversion and find the files /httpd/mod_dav_svn.so and mod_authz_svn.so. Copy these files to the Apache modules directory;
    • Copy the file /bin/libdb*.dll and /bin/intl3_svn.dll from the Subversion installation directory to the Apache bin directory;
4. Configure Subversion and Apache HTTP Server
Edit Apache's configuration file (usually C:\Program Files\Apache Group\Apache2\conf\httpd.conf) with a text editor such as Notepad and make the following changes:
Uncomment (remove the '#' mark) the following lines:
    #LoadModule dav_fs_module modules/mod_dav_fs.so
    #LoadModule dav_module modules/mod_dav.so
Add the following two lines to the end of the LoadModule section.
        LoadModule dav_svn_module modules/mod_dav_svn.so
    LoadModule authz_svn_module modules/mod_authz_svn.so
b. At the end of the config file add the following lines:
    <Location /svn>
         DAV svn
         SVNListParentPath on
         SVNParentPath D:\SVN
         #SVNIndexXSLT "/svnindex.xsl"
         AuthType Basic
         AuthName "Subversion repositories"
         AuthUserFile passwd
         #AuthzSVNAccessFile svnaccessfile
         Require valid-user
     </Location>

c. This configures Apache so that all your Subversion repositories are physically located below D:\SVN. The repositories are served to the outside world from the URL: http://MyServer/svn/ . Access is restricted to known users/passwords listed in the passwd file.

d. To create the passwd file, open the command prompt (DOS-Box) again, change to the apache2 folder (usually c:\program files\apache group\apache2) and create the file by entering

           bin\htpasswd -c passwd <username>

This will create a file with the name passwd which is used for authentication. Additional users can be added with

          bin\htpasswd passwd <username>

e. Restart the Apache service again;

f. Point your browser to http://MyServer/svn/MyNewRepository (where MyNewRepository is the name of the Subversion repository you created before). If all went well you should be prompted for a username and password, then you can see the contents of your repository.
5. Create SVN repository and access it through HTTP
    • Create a folder on your local disk (under the folder where you specify in Apache http server to be the root folder of your SVN);
    • Right click on the folder and use the TortoiseSVN context menu “Create Repository Here”;
    • Access your SVN repository through HTTP as http://server:port/svn/repositoryName/ (you need to type in username and password).

3 comments:

  1. I'm not able to install subversion with the link you gave. Any alternative available?

    ReplyDelete
  2. Hi,

    I'm unable to download the Subversion from the given url. Please give the correct url to download.

    Thanks,
    Mahesh.

    ReplyDelete
  3. You can refer below link for linux base ..

    http://www.linuxfromscratch.org/blfs/view/cvs/general/subversion.html

    ReplyDelete