Thursday, April 21, 2011

Setting up Subversion on Mac OS X Server

In the past I used to use CVS locally on my machine. I loved CVS, but I love Subversion even more.

I have recently purchased a Mac OS X server running Snow Leopard (Mini Server). I comes pre-loaded with lots of stuff, including a web server based on Apache2. I decided  that this is a good opportunity to move all my code from local files, regularly backed up - to SVN.

I wanted my repository to be accessible easily using HTTP and also the ability to view it using a browser. In addition, although I'm the only programmer in the house, I wanted stuff checked-in to the repository be authenticated.

I took me quite some time as the built-in server gave me some troubles, but eventually I made it. Here's how:

Step 1 - Create a Repository

At first, I created the repository under 'svn' directory under my home folder (~/svn). I then decided that who knows, maybe my 3 month old son :) would use it some day - so opted to create it under /Users/Shared/svn:

> cd /Users/Shared
> mkdir svn
> svnadmin create svn

I wanted the repository to be accessible using HTTP, so I added:
> chown -R www svn

It is recommended to create at least one file or directory in this repository:
> cd ~
> svn co file:///Users/Shared/svn
> cd svn
> mkdir projects
> svn add projects
> svn ci


Step 2 - Make the Repository Accessible using HTTP

To access the repository using HTTP, I used Snow Leopard's built-in Apache2 server. This step can be done almost entirely using Terminal (command line) - with root privileges either by logging in as root 'su' or using the 'sudo' command. In the following I assume you're logged in as root (su):

First, stop the HTTP server:
> apachectl stop

Create a file named: /etc/apache2/extra/httpd-subversion.conf (create the 'extra' directory if needed - or choose another directory entirely) with the following contents:
<Location /svn>
   DAV svn
   SVNPath /Users/Shared/svn
</Location>

In /etc/apache2/httpd.conf, add:
# Subversion
Include /private/etc/apache2/extra/httpd-subversion.conf

Also, uncomment the following lines (remove the '#' at the beginning of those lines):
LoadModule dav_svn_module libexec/apache2/mod_dav_svn.so
LoadModule authz_svn_module libexec/apache2/mod_authz_svn.so

We're almost done. Now, go to Server Admin and and click on 'Web' under the server you're configuring. Click 'Sites' on top. Choose the default site and then click 'Options'. Check the 'WebDAV' option and click 'Save'.




Back to the command line, start Apache:
> apachectl start

...or, in Server Admin, click 'Start Web' (bottom left).

This should conclude step 2. Test it by opening Safari on the server and go to the following URL:
http://localhost/svn

You should see the root directory of your repository. If you created the 'projects' directory as mentioned above, you should see it there.


If it doesn't work, look at the web server's logs (Server Admin -> Web -> Logs). If there are no logs, Apache wasn't able to start - probably because of an error in httpd.conf or httpd-subversion.conf. Look at the server's logs (Server Admin -> your server name -> Logs; choose 'System Log' at the bottom).


Step 3 - Enabling Authentication

Assuming your server is configured with Directory Services, this is really a simple step.

Go to Server Admin -> your server -> Web (on the left). Click 'Sites' and choose the site under which you have configured /svn. Now click 'Realms':

On the left pane ('Realms'), click the '+' button at below the Realms box, and add the following info:

Click OK and then click on the Realm you've just created. On the right pane (Users & Groups), click the '+' button at the bottom and add users and groups you with to grant access to the repository (just drag them into the 'Users & Groups' box). When done, close the 'Users & Groups' selection window and make sure to configure the permissions you wish to grant to each user or group you've added.

Once done, click 'Save'.

Test your new setup using the same URL as above. You should now be prompted for username/password before you're granted access to the repository.

Note: the authentication method described above is not secure. You may want to consider using https instead for a more secure setup. Refer to the first link provided below for more information.



This post is based on the following articles:
Installing a Subversion server on Leopard
How To: Manage Your Own Subversion in Leopard
Subversion on OS X Leopard Server

No comments:

Post a Comment