Wednesday, October 31, 2007

How To: Manage Your Own Subversion Repository In Leopard

Mac OS X 10.5 Leopard ships with Subversion 1.4.4 pre-installed. It also ships with Apache2 pre-installed. It does not, however, ship with a pre-installed subversion repository configuration.

So let's say you want to create your own subversion repository host on your Leopard box your own source code management goodness?

You could go to the subversion homepage and download the free svn book and sort through the instructions trying to figure out how they apply to you... Or you could follow these simple directions which I've laid out for you.

Make a Repository

The first thing you need to do is to make a repository. Actually, for my needs, I had to make multiple repositories, so these instructions will set everything up to make that work. It really only changes two steps anyway, so it isn't a big deal.

Now I decided to make my repository collection root directory be in /Users/Shared/, but you can really make it be anything you want, including the ever popular /usr/local. Just be sure to replace /Users/Shared/ with your directory of choice whenever necessary.

Anyway, I opened Terminal and entered the following commands:

$ sudo mkdir /Users/Shared/svn
$ sudo mkdir /Users/Shared/svn/reposname
$ sudo svnadmin create /Users/Shared/svn/reposname
$ sudo chown -R www:www /Users/Shared/svn/reposname

Note that you can create multiple repositories by following these directions but replacing every instance of reposname with the name of the repository you want to use. Thus, if you have multiple repositories, you will have multiple directoris in /Users/Shared/svn

Make Access

Most directions do this later, but I'm going to do it now because I think you are smarter than that.

You might want to create a passowrd file, unless you want full public access to your repository. For our purposes, simple http basic authentication is fine, but remember that the password is only weakly encoded and the traffic isn't encoded at all, so a snooper could get to the information if you access your computer outside of your own computer.

So if you do want to use authentication, create the password using the following command, substituting username for a user name of your choice, and following the directions for password creation:

$ sudo htpasswd -cm /etc/apache2/svn-auth-file username

To add other users to the file, just ditch the c switch in the -cm options to htpasswd. The c stood for create, and since the file has been created you don't want it anymore.

Note that you can put the svn-auth-file anywhere you want, but this seemed like a good place for it in my mind. (Just remember where you hid it from yourself if you put it anywhere else.

Apache Configuration

Navigate to /etc/apache2/other and use your favorite command line text editor as root to make a file named anything you want (I chose svn.conf, but you could name it foobar_banana.conf and it would still work!):

$ cd /etc/apache2/other
$ sudo vim svn.conf

Now that you are editing this file as root, you want to make it contain the following bits, and save:

LoadModule dav_svn_module /usr/libexec/apache2/mod_dav_svn.so

<Location /svn>
    DAV svn
    
    SVNParentPath /Users/Shared/svn
    
    AuthType Basic
    AuthName "Subversion repository"
    AuthUserFile /etc/apache2/svn-auth-file
    Require valid-user
</Location>

Note that you can leave off all the authentication related stuff if you didn't want authentication on your repository. Also note that you need to fix the SVNParentPath and the AuthUserFile if you varied from my directions.

Restart Apache

Now restart Apache. This can be done in the Sharing panel of the System Preferences application. Just click to turn off, and then back on, Web Sharing.

Now, if you didn't make a mistake, you should be ready! Try going to http://localhost/svn/reposname (where you need to put the repository name you chose earlier instead of reposname!) and see what happens.

If you are lucky you'll see revision 0 of your repository. But most people are human and will have made a typo that results in an error. For hints on what created the error, trying checking out /var/log/system.log and /var/log/apache2/error_log for hints as to what you did wrong. (And as a bonus, the Console application works great for monitoring thes logs as they are writen to!)

Where From Here?

And now you are ready to use your repository. At this point I figure you already know how to use SVN and don't need my help anymore. But if you need to know how to use SVN, just refer to their book, which tells you everything you need to know, including how to make your server better!

EDIT (11/6/07): Forgot to encode my character entities in the example script source. I fixed this so that the <Location> tag actually shows now.

EDIT (04/23/08): The chown line now uses the full path as it should. Thanks to all those who pointed this confusion inducing mistake out.

27 comments:

Michael Plank said...

Hi, thx for the tutorial, but it doesn't work on my system. /var/log/system.log says:

com.apple.launchd[1] (org.apache.httpd): Unknown key: SHAuthorizationRight

org.apache.httpd[887]: Syntax error on line 2 of /private/etc/apache2/other/svn.conf:

org.apache.httpd[887]: DAV not allowed here

Any idea about this problem?

Paploo said...

My bad. I forgot to encode my character entities in my example, so the Location tags got left out.

I bet that'll fix it now.

Michael Plank said...

Thanks a lot!! Now everything works like a charm!!

Michael Plank said...

I have troubles with my os x svn server on some Windows Machines. Can't check out or import projects. Problems like "RA layer request failed .... 400 Bad Request..." occur and I don't figure out why. Can anyone help?

Paploo said...

Michael: I'm no sure why you are getting that error. A quick google search isn't really giving anything helpful other than "something must be wrong with the network configuration." So you might want to make sure there are no proxies or firewalls interfering.

You also will want to make sure the Windows machines are running subversion 1.4.x, just in case that has anything to do with it.

Otherwise I wish you luck, and if you figure it out, I encourage you to post the solution here so that others can benefit from it.

Anonymous said...

Thanks mr Paploo, its not that I don't want to dive into the subversion manual for a few hours. Its that I did, and then did everything stated there in proper order, and then ended up with obscure errors with apache, that turned up empty in google. But that was on 10.4., now it is 10.5 and everything is working a charmy charm after 10 minutes. Wahoo!

Jack said...

You actually don't need to make the directories. Just issuing the "svnadmin" command will make the directories for you.

Sena said...
This post has been removed by the author.
Trevor Smith said...

For real beginners, your instructions above will likely cause some head scratching:

$ sudo mkdir /Users/Shared/svn
$ sudo mkdir /Users/Shared/svn/reposname
$ sudo svnadmin create /Users/Shared/svn/reposname
$ sudo chown -R www:www reposname

That last line will likely not work. You will need to either be explicit, as in:

$ sudo chown -R www:www /Users/Shared/svn/reposname

or change into the svn directory first, as in:

$ cd /Users/Shared/svn
$ sudo chown -R www:www reposname

Anonymous said...

Great post, thanks. Just what was needed!

Anonymous said...

Actually I am getting a access permission error, like "you don't have permission to access svn/projects" on this server, it is also showing this error when i try to access a different folder outside my local user. Do somebody knows why this behavior? thanks you very much for this lovely post, very useful!

Alex said...

Just googled this up and it worked perfectly on 10.5.2. Thanks, dude!

Handy said...

Thank you, Jeff!

Your tutorial works fine on my Leopard!

I want to put everything in my home directory (e.g. /Users/my_user/Projects/svn), thus I modifed the directory path and the svn.conf file.

Allan said...

I was hoping to use an encrypted sparse image called "svn" as my subversion repository collection root (SVNParentPath /Volumes/svn), but I keep getting this in my console:

com.apple.launchd[1] (org.apache.httpd): Unknown key: SHAuthorizationRight

and this message in my Safari:

"Could not open the requested SVN filesystem"

Should I just give up and put my repository collection root in usr/local instead? Or am I missing some magic command to make this work?

Any advice would be awesome ^_^.

Paploo said...

allan: I don't know if what you want to do would work or not. It would be neat if it did, and I would expect it to work, but I never ceased to be surprised by the funky things that happen sometimes. :)

Allan said...

I might have bitten off more than I can chew with this whole "encrypted disk image as svn repository collection root" idea, I think I'll give up (for now).

Thanks for responding to my comment so quickly!

:D

Anonymous said...

I followed all instructions and was able to install the repository without a hitch. I later decided I wanted the repository in another location and removed the original one creating a new one and modifying the appropriate files. Now I can't get the repository to load in Safari. In the error_log:
[Sun Mar 09 20:13:06 2008] [error] [client ::1] (20014)Internal error: Can't open file '/Users/pete/Documents/xcode/svn/defaultRepository/format': Permission denied
[Sun Mar 09 20:13:06 2008] [error] [client ::1] Could not fetch resource information. [500, #0]
[Sun Mar 09 20:13:06 2008] [error] [client ::1] Could not open the requested SVN filesystem [500, #13]
[Sun Mar 09 20:13:06 2008] [error] [client ::1] Could not open the requested SVN filesystem [500, #13]

Any suggestions?

Paploo said...

Anonymous: It sounds like one of two things happened.

Firstly, make sure you ran the chown command to set the user and group to 'www'.

If that doesn't work, try setting the permissions on the repository with chmod. I'd think recursively setting the permissions to 755 would work fine, but that could be overly open if you have other users logging onto the system that you don't want snooping through the directory.

Anonymous said...

Thanks!!! Great blog post and very useful. I've been wanting to know how to do this and now I can.

-- Iain

Matthew said...

Wow, this is amazing! What a great resource. I'm having trouble with one part, I'm not quite sure I understand what you mean when you say:

"Navigate to /etc/apache2/other and use your favorite command line text editor as root to make a file named anything you want"

--can you elaborate?

Thanks for all the help!

Paploo said...

Matt: I'm glad you are finding the instructions useful. Here is some more elaboration on "Navigate to /etc/apache2/other and use your favorite command line text editor as root to make a file named anything you want":

From the command line you'll want to run:
$ cd /etc/apache2/other

Now you need to pick a favorite command line editor. I use vim. Emacs is another favorite. I also like JOE a lot, but you'd have to compile that one yourself. (If you don't know how to use these, you can find plenty of documentation on the internet about them. If you plan on doing dev kind of stuff on a UNIX machine, being comfortable with either vim or emacs is a must-have-skill.)

So let's say you pick vim, and let's say you want to create the file matt_svn.conf for your configuration file. You could then execute:
$ sudo vim matt_svn.conf

And that should get you caught up to where the instructions should work for you again. :)

marty said...

Fantastic tutorial and worked like a charm. Been trying to sort this out for ages. Now I just need to get https working so I can put it out on the internet for my developers.

Jeff Foster said...

I have to confess I have been to this page probably 5 different times over the last few months to get Subversion running on my machine and am really frustrated.

The instructions for the .conf file are still somewhat hazy. I have never used a command line text editor, but in this case i chose emacs. I attempted to create the file and save?(does it autosave?). Whether it was saved or not, here are some questions about the .conf file I am unclear about:

1. in the tutorial, it has become confusing because you use "svn" for the name of your directory, but "svn" can also mean something totally different when in the command line. i am having a hard time distinguishing between the two, not to mention figuring out when to substitue my named directory for "svn" in your instructions.

2. does emacs "autosave"?

3. Would you be willing to help using ichat screen sharing, or know someone that can?

Any help would be appreciated, i have wanted to use subversion on my machine for months, but some kind of mental block is stopping me every time i try.

Paploo said...

Jeff Foster: It sounds like your primary problem is a lack of understanding the fundamentals of the command line environment.

While it is nice to have instructions that assume you don't know anything about the CLI, it is my experience that most of these sorts of things require a certain ability to cope with the usual unexpected problems that seem to pop-up for whatever reason.

I would recommend that you first learn the basics of how the command line works (the difference between a command and an argument for instance).

Then you should find a tutorial to emacs (or vim), and play with it a little. Try making a text file in your home directory (so that you can use something like TextEdit to verify the contents of the file) and play with the editor a little until you understand the basics.

It might take you an hour or two to find these two kinds of tutorials and go through them, but I promise you it'll open a *large* world in computing to you.

To answer your questions more directly:

1. Learn the difference between a command and an argument. It should eliminate the confusion when reading the command line instructions.

2. I don't use emacs (I prefer vim), but I'm 99% sure it does NOT autosave.

3. Unfortunately I lack the time to walk you through the process remotely, and I do not know anyone that could do that for you. However I'm sure that once you've taken the time to learn the basics of the command line interface it'll all start to click for you. :)

Good luck, and if you find a tutorial on these subjects that you like, I encourage you to post the links here so that others can benefit from it. (There should be a plethora of these on the internet.)

Simon Wolf said...

Wonderful, thank you. As a newcomer to Mac development and Subversion this was a really helpful guide.

Anonymous said...

Hi, thanks for a very nice writeup, but perhaps consider to include the full path in the line with chown, confusing.

About using a truecrypt image or a secure sparse image; this can be easily implemented by configuring cccloner to sync in and out of the image - as an example on insertion of a memory stick.

Neezer said...

I couldn't get this to work when I created a directory in a user account with FileVault enabled, FYI. Setting it up in the Shared User folder works fine, though.