Saturday, March 13, 2010

Setting up Subversion with Apache


Set up Apache

1. Download the latest version of Apache Server from
http://httpd.apache.org/download.cgi

2. Follow the instructions and install the apache server.

3. Make sure apache server is running as a windows service which is recommended. It will also help you access via http to SVN if apache is running in the background as a windows process. Rather than having to manually manage it.


Set up Subversion

1. Download subversion from
http://subversion.apache.org/packages.html. These instructions are for windows. So make sure you select the svn version for windows and also make sure that you select a version compatible with the version of apache installed above.

2. Create your repository. Open up a command window and go to the \svn\bin dir. To create a repository run the following command - svnadmin create "c:\svnRepo\repo1" where svnRepo is the location where you want to put in multiple repositories and repo1 is one of the repository that you will be creating.

3. Next start your repository by running the following command - svnserve --daemon --root "c:\svnRepo" which will start all repositories under \svnRepo.

4. You will probably want subversion to run as a windows service though. You can create a windows service by running the following command on your command prompt - sc create svnserve binpath= "C:\........\svn\bin\svnserve.exe --service --root C:\svnRepo" displayname= "Subversion Repository" depend= Tcpip

5. Next edit the svnserve.conf file, located at /svnRepo/repo1/conf, to provide information for svn access. in its most simplest form the file contents would look something like this

[general]
# disallow anonymous accesss
anon-access = none

# location of the password file
password-db = passwd

# location of the authentication details
authz-db = authz

6. Next edit authz file. my configuration looks like below. For now I have an admin group which has one user - admin1 and a developer group. The admin group has access to the entire repository. The Developer group has full access to only the code dir in the repository but has read rights to the entire repository.

[groups]
svn_admin = admin1
developer = dev1
[/]
@svn_admin = rw
@developer = r

[/code]
@developer = rw


7. Edit passwd file to add passwords for the users.
[users]
admin1=admin1
dev1 = dev1

8. Obviously the above is the simplest form of set for SVN. You can also configure your repository to have users from LDAP for eg.

9. To manage and work with your repository Tortoise SVN is a good tool. Install from this link
http://tortoisesvn.net/downloads.

10. Once you are started your repository (as a windows service) you can access your repository using TortoiseSVN. Right-click anywhere in windows explorer and select TortoiseSVN - > Repo-browser option. In the dialog box that opens up type in "svn://localhost/repo1". You will be prompted to authenticate. Use one of the admin accounts created above. Now you should be able to view your repository contents. You can go ahead and create the code directory and set it up as you please.

Getting Subversion to work with Apache

In the set up as described above we were accessing svn directly. Now we set up Apache so that it integrates with SVN.

1. Shut down apache and copy the following files from SVN - \svn\bin\mod_authz_svn and \svn\bin\mod_dav_svn to \apache\modules\.

2. Next we need to create passwords for the users defined in SVN's authz file. We cannot use the passwd file configured above anymore. Open up a command window, go to \apache\bin dir and run the following command - htpasswd -c passwd admin1. You will be prompted to enter a new password. After you are done you should see a new file passwd under the bin folder which should store the password in encrypted format. For creating passwords for subsequent users you do not need to use the '-c' option since that is only used for creating a new password file. for eg - htpasswd passwd dev1.

3. Next open up the \apache\conf\httpd.conf file and uncomment the following entry.
LoadModule dav_module modules/mod_dav.so
and add the following entries
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

4. Finally add the following

#access by http://localhost/svn/<repo-name>
<location>
DAV svn
SVNParentPath c:/svnRepo #path to parent repository
AuthType Basic
Require valid-user #valid user is needed
AuthName "Subversion repository"
#paswd file created above
AuthUserFile C:\apache\bin\passwd
#svn authz file created above
AuthzSVNAccessFile C:\svnRepo\repo1\conf\authz
</location>
5. Restart Apache. Now you should be able to access SVN in the browser using the url - http://localhost/svn/repo1 or you can also use the same url in Tortoise SVN.

No comments:

Post a Comment