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.

53 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 comment 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.

mattnolan said...

Hi, great tutorial. Really easy to follow and everything works well.

I now would like to use subversion 1.5 rather than the pre-installed version. I've installed binaries in /usr/local/bin
and after updating PATH can run version 1.5 as expected from the command line. However, I can't figure out how to make apache use the new version at /usr/local/bin rather than the pre-installed version at /usr/bin. Any suggestions?

Anonymous said...

Thank you so much for this easy and quick tutorial. People like you make this World a better place!

Vishesh said...

That was simple and easy. Thanks a bunch!

bberg said...

created the repos just fine. used the auth conf described. now how can i import (svn import etc...) a tree into the repos? i get a permission denied.

lee said...

I'm receiving the error.
svn: PROPFIND request failed on '/svn/myRepo'
svn: Connection refused

If I try accessing via MAMP's localhost:8888 the connection attempt just times out.

There doesn't seem to be any info in the system.log, and there isn't an error_log in the apache2 directory

Anyone have any suggestions? Much appreciated.

lee said...

Oh, and I'm attempting to connect with both eclipse, and svnX.

Anonymous said...

When I try to access via Safari, it fails to load, reporting that it cannot find the server, 'localhost'.

lee said...

TADA!

I didn't realize Web Sharing needed to be on, in order to access localhost. Thanks Paploo, all is well now! Had to read carefully = ]

Paploo said...

lee: Sometimes just being able to talk the problem out solves the problem. :) Around here we call it "talking to the bear" because of a story about a development manager being bothered by her developers all the time. It turns out these developers would usually figure out the answer without her saying a word, just because they were forced to think about it when choosing words to explain it. To keep people from bothering her, she ended up getting a stuffed bear and when someone would come to her office she'd hand them the bear and say "go to the conference room and tell it to the bear!"

adam g. said...

This is a great tutorial, had my repository up in 5 minutes. I hit a glitch here and there trying to use a different tutorial, but found this one and got it running without any problems and no errors. Thanks for posting this, very helpful.
-Adam

Nancy said...

Hi, Thank you for the post. I followed the exact same directions, however, I am unable to view my repository on Safari. I use the Mac OS server version. This is the error that I found in the apache error_log "File does not exist: /Library/WebServer/Documents/svn". Any ideas on how to fix it?

Anonymous said...

Hi,
same issue with me as Nancy said..

i m also try this all step on my MAC OS X 10.5 server
but not worked
error on explore

"[ Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404
gwn.local
Mon Feb 2 19:21:36 2009
Apache/2.2.9 (Unix) mod_ssl/2.2.9 OpenSSL/0.9.7l DAV/2 PHP/5.2.6 SVN/1.4.4 ]"

error in /var/log/apache2/error_log file
"client 10.0.7.223] File does not exist: /Library/WebServer/Documents/svn "

Please get me out of this.
need yr guidence

thanks in advance

shail
skype : shailesh.vaja
e-mail address : shailesh.vaja@gatewaynintec.in

Mophilly said...

The path /etc/apache2/other does not exist on my install of osx server 10.5. I am going to try "mkdir other" and proceed. Is the directory "other" significant?

Zaph said...

This worked well 6 months ago. Just upgraded my MacMini and now it fails with:
[[error] [client ::1] (20014)Internal error: Can't open file '/Volumes/Archive/svn/iPhone/format': Permission denied

I tried changing the permissions to 755, no good.

So the best I can guess is that Apple/Apache/svn changed something because they don't want this to work for me. ;-)

warpedspeed said...

Great tutorial, exactly what I've been looking for. However, I get to the final step and an error: (160043) Could not open the requested SVN filesystem. Some googling later and I got the same message with a different error code. Permissions maybe?

windsword said...

I am able to see the webharp svn on the browser, but the 2nd one does not show up. I noticed that from the command line, if I try to change directories, only the first one (webharp) allows me and the other does not. Do you have any tips for me?
drwxr-xr-x 9 _www _www 306 Nov 17 2008 webharp
drwxrwx--- 5 _www _www 170 Feb 17 16:37 harmonix

Paploo said...

windsword: It looks like your permissions are set wrong. You should read the man page for chmod, which explains permissions in detail. If you work with UNIX like OSs very often, permissions will very quickly become important for you. (The short answer--remembering that a mistake can hose your system--is that you'll want to "chmod -R 755" the harmonix directory. Be sure however, to run this command ONLY on that directory and its contents. If you accidentally run it on many other directories you stand a good chance of hosing your system. You have been warned! :)

sebasong said...

thx. this work perfectly!

David said...

nancy: Had same problem as you, but had misnamed my snv.conf file - check yours ends .conf

BrotherKev said...

Hey there,

I'm getting the error:

"Could not open the requested SVN filesystem"

when I try to browse to my repository. I'm pretty sure I've got all the permissions set properly, and my apache config just as you describe it above. My svn.conf file is:


LoadModule dav_svn_module 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>


My httpd.conf file has this line:


# Subversion
Include /private/etc/apache2/extra/httpd-subversion.conf


Permissions on /Users/Shared/svn:


drwxrwxrwx 3 _www _www 102 Sep 30 12:23 svn


and on /Users/Shared/svn/drupal1 (which is my repository directory):


drwxrwxrwx 8 _www _www 272 Sep 30 12:24 drupal1


These permissions are all 777, because I tried with 775 on both dirs and that didn't work either.

I built the svn-auth-file just as you described.

Any clue where I should look next?

BrotherKev said...

Okay, I fixed the problem I mention above.

My problem was that I had upgraded from subversion 1.4.4 (Leopard's default) to 1.6.4. But I was still using the mod_dav_svn.so and mod_authz_svn.so files from version 1.4.4. My newer subversion binaries were installed under /opt, and Apache was looking for them under /usr/libexec/apache2/. So I just replaced those two files with the newer versions, and now it works.

Subversion repositories created with 1.6.4 are unreadable by 1.4.4, so naturally, I got that error.

If you want to check which svn version apache is using, just check your apache error log (/var/log/apache2/error_log) and look for a line like this:

[Thu Oct 01 09:28:23 2009] [notice] Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.7l DAV/2 SVN/1.6.4 PHP/5.2.9 configured -- resuming normal operations

You can see the SVN version number there. It just needs to match what you get when you check the svn version on the command line:

svn --version

Hope this helps someone!

macbook 13 said...

Thanks for the blog, very informative and helpfull information, thanks again.

capslock said...

First time ever i followed a tut and everything just ... worked!
Thanxxx!

Patrick said...

Hi, this looks to be a great tutorial but I can't get the first test to work and I am not sure what I am doing wrong. I followed every step to the letter, copied and pasted and I am still getting the "Could not open the requested SVN filesystem"

This is the error that I am getting in the apache2/error_log
[Sun Sep 26 03:02:39 2010] [error] [client ::1] (20014)Internal error: Expected FS format '2'; found format '4'
[Sun Sep 26 03:02:39 2010] [error] [client ::1] Could not fetch resource information. [500, #0]
[Sun Sep 26 03:02:39 2010] [error] [client ::1] Could not open the requested SVN filesystem [500, #160043]
[Sun Sep 26 03:02:39 2010] [error] [client ::1] Could not open the requested SVN filesystem [500, #160043]
[Sun Sep 26 03:02:39 2010] [error] [client ::1] File does not exist: /Library/WebServer/Documents/favicon.ico, referer: http://localhost/svn/reposname

Any thought or suggestions would be helpful.
Thanks,
Patrick

Anonymous said...

First time I did it - it didn't work.
Started over again and found where I went wrong.
If you copy and paste (from this site) the contents of that svn.conf file, the first few letters (Loa) get cut off. Must be a VIM quirk.
I typed it manually from scratch.
This time it worked completely fine.

Anonymous said...

How about router ports?
Which ports should be forwarded?
80?
Can you configure the SVN server to use different ports or is that dictated by apache?