Setting up a Subversion on Leopard (OS X 10.5)...

This is much easier in Leopard.

Here's how:

First off, we have to set up Apache2. Prior to Leopard, this was complicated, as Tiger shipped with a 1.x version of Apache, and the Subversion module only worked with version 2. Since Leopard comes with Apache 2 by default, and when you install XCode 3 you get subversion, you have everything you need, and you only have to perform configuration. We'll change the port we liste on from port 80 to port 8008, tell Apache to load the shared libraries that it will need, and setup a "svn" directory location, where we will serve the repository from:

  1. First, in Terminal, cd /private/etc/apache2
  2. Now let's open the file for editing, using the "vi" editor: sudo vi httpd.conf (We use vi because it will allow you to save it directly over the existing configuration file, since we are running it with superuser privileges)
  3. In the file, we'll first change the port we'll listen on from port 80 (the standard http port), to port 8008: Listen 80 becomes Listen 8008
  4. Next, we have to tell apache to load the modules we need, specifically the dav svn module, and the svn authorization module. Conveniently, these two modules have already been compiled, and are available in the libexec directory under apache2, so all we have to do is add them to the httpd configuration, below the other LoadModule lines in httpd.conf
    • LoadModule dav_svn_module libexec/apache2/mod_dav_svn.so
    • LoadModule authz_svn_module libexec/apache2/mod_authz_svn.so
  5. You'll notice that on the last line of httpd.conf, that it includes everything in the "other" directory. So we'll put our svn configuration file there:
    • cd other
    • sudo vi httpd-svn.conf
    • <Location /svn>
        DAV svn
        SVNParentPath /Users/rmartell/repositories
      </Location>
      1. Now that Apache has the basic setup, we need to create the repository directory, and create a repository in that directory:
        1. Create the directory we specified in the httpd-svn.conf file
          • cd /Users/rmartell
          • mkdir repositories
          • cd repositories
        2. Use the svnadmin tool to create the actual repository:
          • svnadmin create Sample
          • Since Apache, by default, runs under the www account, so does the Subversion server. We need to give ownership of the files in the repository to www, so that the server can write to them
            sudo chown -R www Sample
        At this point, we are totally setup, so we need to start Apache. In the System Control panel, go to Sharing, the click on Web Sharing. This will start Apache2. To verify everything is working, in the Terminal we can use the command line svn tool to list the files:
        svn list http://localhost:8008/svn/Sample
        Or we can point our browser at it, by typing in http://localhost:8008/svn/Sample into the address bar. There is nothing listed currently, because we have nothing in the Repository yet. I'll go into adding files (and working with the repository) in a later post. But you shouldn't see any error messages!

        We could stop there, but currently anyone in the world that knew where our Repository was would be able to download our code, as well as make changes to it. Since this isn't a great idea, we're going to add basic authentication:
        1. cd /private/etc/apche2/other
        2. sudo vi httpd-svn.conf
        3. Below SVNParentPath, we add:
            AuthType Basic
            AuthName "Subversion Repository"
            AuthUserFile /private/etc/apache2/svn-auth-file
            Require valid-user
        4. Now we have to create the authorization file sudo htpasswd -c svn-auth-file username (we enter our password twice- this is the Subversion user password, not our administrator password!)
        5. That's done, so to test it, we enter into our browser address bar http://localhost:8008/svn/Sample and it will present us with a login box for the Subversion Repository Realm. When we enter our username and password, we will connect!


        Now you have to have a login to check out the code or to check code in. If you were working on an open source project, and wanted everyone to have access to the code, but only registered users to be able to check the code in, you can modify the httpd-svn.conf file appropriately:
        1. cd /private/etc/apache2/other
        2. sudo vi httpd-svn.conf
        3. Replace Require valid-user with
          <LimitExcept GET PROPFIND OPTIONS REPORT>
            Require valid-user
          </LimitExcept>


        And you're done!

        When I get around to it, I'll show how to use the SCM features on XCode to connect to your repository, as well as how to add SSL to your repository! Hope you found this useful!