Setting up Subversion Environment

[article]

This article describes the SVN installation on both server and client sides. Depending on the setup required, SVN installation could be anything from trivial to a nightmare.

We will describe the most common setup: accessing SVN via HTTP protocol using the Apache HTTP server, which is much closer to trivial than to nightmare. We have chosen this setup, since it seems to be the most common and also it’s a basis for more advanced setups (e.g. for LDAP integration). The steps are following:

    • Install Apache HTTP Server
    • Install Subversion
    • Configure Apache with Subversion

If you wish to live without Apache, then you can consult the Subversion Book or the Links section which points to some other tutorials on installing SVN with svn: protocol access.

Installing Apache
Subversion requires Apache 2.0.x edition (not the latest 2.2.x). The MSI installer can be downloaded from http://httpd.apache.org/download.cgi. Don't forget to choose the 2.0.x version. After downloading, start the installer and go thought the installation screens. When leaving the default values, you should end up with Apache installed as a Windows service and running on port 80. If you run some personal firewall or similar protection software, make sure to disable it so that it does not block any installation steps. Also, some communication programs, like Skype, occupy the port 80 by default, so it's safer to close them in advance. After the installation is finished, you will see the feather-like Apache status icon in the taskbar. Pointing your web browser to localhost will display Apache's welcome screen. That's all for basic Apache's installation.

Installing Subversion
The 'Downloads' section at http://subversion.tigris.org/ contains the link for the user-friendly exe installer. It contains components for both client and server side. During the installation make sure to check the option to install the Apache modules. After the installation is complete, the Subversion documentation icon should appear on your desktop. It's a Windows-help version of the Subversion Book, which contains the most complete information on any topic related to Subversion. Now, if you open the console window and try to type the svn or svnadmin command you will get the help screen (if not, then you might need to restart/relogin to update your path system variable).

Configure Apache with Subversion
The Subversion installation modifies your Apache configuration file to load the modules, which handle the Subversion requests. Now we will finalize the configuration by pointing Apache to your SVN repository. Open the httpd.conf file (usually in "C:\Program Files\Apache Group\Apache2\conf") and add the following text to the end: DAV svn SVNParentPath C:/SVN This tells Apache that all subfolders of C:/SVN are SVN repositories which will be accessible via the /repos URL.

Restart Apache for the settings to take effect (use the feather icon in your icon tray). Now, execute the following command to create the repository: c: mkdir \SVN cd \SVN svnadmin create sandbox. The last command creates the new SVN repository with name sandbox. Pointing your browser to localhost/repos/sandbox/ will now show the content of the repository revision 0 (zero). Note that we did not have to restart the Apache to add the repository.

Those, who prefer to have just one repository might use SVNPath instead of the SVNParentPath directive in httpd.conf and give the path up to the repository folder (e.g. c:/SVN/sandbox/ in our case).

Adding security
Now we have the repository created and accessible, but there are no restrictions and logins required, which is something we definitely don't want. Therefore we will add some security to our repository. We start with authentication (who you are) and then proceed to authorization (what are you allowed to do). In the basic setup, the Subversion uses the password file to store the user names and their (encrypted) passwords.

Change the Subversion section in httpd.conf to this DAV svn SVNParentPath C:/SVN Require valid-user # how to authenticate a user AuthType Basic AuthName "My Subversion repositories" AuthUserFile "c:/SVN/passwd" and restart Apache. The content of the passwd file is managed using the htpasswd.exe utility, which is located in Apache’s bin folder.

Run this command inside the bin folder:

htpasswd.exe -b -c c:\SVN\passwd tutor tutorpass

to create the passwd file (-c option) and add the user 'tutor' with password 'tutorpass' (the -b option tells, that we want to specify the password as parameter).

If you now point your browser to the repository URL (localhost/repos/sandbox/) the login window will appear asking for credentials. Failure to give valid credentials will result in "Authorization Required" error screen. Once the correct credentials are provided the browser session will remember them until it's closed, so you have to restart browser to 'logout'. Now the repository requires all users to login, but you get either all rights or none. Therefore we will add the settings to fine-tune the authorization. Add the new lines to our httpd.conf file section so that it looks like this:

DAV svn SVNParentPath "C:/SVN" # our access control policy AuthzSVNAccessFile "c:/SVN/access" # try anonymous access first, resort to real authentication if necessary. Satisfy Any Require valid-user# how to authenticate a user AuthType Basic AuthName "My Subversion repositories" AuthUserFile "c:/SVN/passwd" The first statement points to the access file location and "Satisfy Any" enables anonymous access (if not disabled by the access file). Don't forget to restart Apache after doing the change. Then create the access file with the following content:

# Group definition [groups] trusted = tutor, john

# Default access for all repos [/] * = @trusted = rw

# Sandbox is opened for everyone [sandbox:/] * = rw

[sandbox:/serious] * = r tutor = rw

In the first section we define groups and users assigned to them. In the following sections, the access rights for individual locations are specified. The read (r) and write (w) rights are distinguished, we can also specify no right (=no access at all). The star character stands for every user (including anonymous access). When assigning the right to a group, we have to add the @ character before the group name. The rights are inherited down the folder structure, but can be overridden (e.g. we give full anonymous access to the root of sandbox, but only anonymous read to the serious folder). As with the passwd file, changes in the access file apply immediately and they don't require Apache restart.

To test the access rights you might now create some additional users using the htpasswd.exe utility (make sure to leave out the -c parameter, otherwise you will overwrite the old file) and some more repositories using 'svnadmin create repo_name'. You can also try 'svn help mkdir' to learn how to create the serious folder, or you might rather proceed with installing TortoiseSVN and then create the serious folder in a more user-friendly way.

Installing Tortise SVN
TortoiseSVN is graphical SVN client, which integrates into Windows Explorer context menus and makes working with SVN in Windows really easy. Download the MSI installer from the project page http://tortoisesvn.sourceforge.net/ and run through the installation, keeping the default values. After the installation is finished (and after reboot on some Windows versions), the TortoiseSVN menu items will appear in the Windows Explorer context menu. If you see them, your TortoiseSVN is installed successfully.

Now you can create the serious folder through the Tortoise GUI. Right-click somewhere in Windows Explorer, select TortoiseSVN->Repo-browser and enter the repository URL (localhost/repos/sandbox/). The repository browser will appear showing the empty repository. Right-click the root node, select 'Create folder...', enter 'serious' and then 'Creating the serious folder' as the commit message. In the next window type in the credentials (you can tell Tortoise to remember them) and voila, the new folder is created. Now right-click the root node and choose 'Show log' - you will see the information about the commit you just made.

This was the final exercise in this part of the series. You can now start playing around with your repository using TortoiseSVN or the command line clients (svn and svnadmin). The documentation that came with Subversion (remember the icon on your desktop) and TortoiseSVN can help you. Or you can wait for the next part of this Subversion series, which will bring the guided tour through the most frequent Subversion use cases.

Is this all?
For those, who are eager to install something more, this last section provides the brief listing of other clients and useful tools for Subversion. The following list does not aim to be complete - there are many more SVN tools available these days. It's just the selection of free tools, which I consider to be representative in some way, or which attracted my attention by some nice features.

Other Clients
RapidSVN - cross platform GUI client written in C++ - http://rapidsvn.tigris.org/ SmartSVN - cross platform GUI client written in Java - http://www.smartsvn.com/

IDE Integrations
Some IDEs, like IntelliJ IDEA or Borland JBuilder have the Subversion support built-in. For others, like Eclipse or MS Visual Studio, there are external plugins, which provide SVN integration.

Subversive - plugin for Eclipse - http://polarion.org/

Subclipse - another plugin for Eclipse - http://subclipse.tigris.org/

AnkhSVN - addin for MS Visual Studio - http://ankhsvn.tigris.org/

Web Interfaces
SVN Web Client - web interface for browsing repository content and doing simple modifications, written in Java -http://polarion.org/

Other projects
FastTrack - Issue Tracker plugin for Eclipse, which stores data in SVN - http://polarion.com/ JavaSVN

Links

Subversion - http://subversion.tigris.org/
Apache HTTP Server - http://httpd.apache.org/
TortoiseSVN - http://tortoisesvn.sourceforge.net/


Michal Dobisek is Software Architect at Polarion Software GmbH ( (http://polarion.com). He has experience with CVS, Perforce and Subversion. He has two years experience in using, administering and tweaking Subversion. He holds a Masters degree in Cybernetics from Gerstner Laboratory of the Czech Technical University in Prague.

About the author

AgileConnection is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.