Subversion Web Repository set-up MICRO-HOW-TO 10 March 2004 Chandler Howell chandler.howell at halfcat.org Please don't hesitate to contact me with any comments, thoughts, corrections, or thanks that may strike you if you find this document useful. DISCLAIMER This is intended to provide a single, unified HOW-TO for performing a minimal subversion web repository set-up. There is nowhere near enough information here to allow for a full-blown, secure repository, so keep that in mind as you follow it. There are numerous considerations, most of them business rather than technical problems, associated with creating and managing a shared or networked source repository. I don't even begin to touch on those, because they invariably wind up turning ugly and I don't need flame mail hitting my inbox. Specifically, though, remember that this repository will be WORLD-READABLE! That means that any "secrets" such as hard-coded database logins or configuration files will be WORLD-READABLE, as well. And if your repository sits on a publically-accessible IP Address, I mean the WHOLE WORLD when I say "world." There...had to get that out. REFERENCES: - Subversion web site: http://subversion.tigris.org - Subverion Book On-Line: http://svnbook.red-bean.com - Subversion FAQ: http://subverion.tigris.org/FAQ (?) CONVENTIONS: Since this is a text document, I use the following conventions to differentiate diffent formats. Commands to be issued from a shell will be explained on the previous line ending in a colon (":") and prefixed by either a "$" or a "#". "$" commands are intended to be executed in a non-root shell. "#" commands are those which require super-user status at the locations I specify. The expected output from the command will be displayed immediately underneath. Commands which are silent by default (i.e. `mkdir`) will simply be followed by a blank line. If a command produces several lines of output, it will be followed by an "---- End ----" separator much like an included file. THE MICRO-HOW-TO: 1) Check for Subversion Subversion is included by default on RedHat 9, Fedora Core 1 (FC1). I can't comment on other distros. Starting with FC1, it has apache support included, as well, although only as a stubbed-out file /etc/httpd/conf.d/subversion.conf. You mostly need to uncomment it and add the referenced pieces (htpasswd, a repository) To check if subversion is installed, you can either... - Look for installed packages: $ rpm -qa | grep subv subversion-0.32.1-1 subversion-devel-0.32.1-1 - From a command-line, run `svn` and see if it's in the path: $ svn Type `svn help' for usage. 2) Create the repository First, create the directory that you're going to put your repositories in. In my case, I'm creating my repository structure at "/var/local/subversion" so I'll create that directory: # mkdir -p /var/local/subversion Now, I can create the repository within it: # svnadmin create /var/local/subversion/repos 3) Configure apache access to the repository. * You should probably look at the On-Line book, Ch. 6 for detail here ( http://svnbook.red-bean.com/html-chunk/ch06.html ) The supplied config file FC1 (/etc/httpd/conf.d/subversion.conf) provides most of what you need. Its contents are, for those of you playing along in the non-FC1 world. Note: Everything in this file except the two LoadModule directives were commented out by default. I'm using my repository I created above (/var/local/subversion) here and my htpasswd file at /var/www/htpasswd: -------- Begin -------- LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so # # Example configuration to enable HTTP access for a Subversion # repository, "/var/local/subversion". This repository must be readable # and writable by the 'apache' user. # DAV svn SVNPath /var/local/subversion # Limit write permission to list of valid users. # Require SSL connection for password protection. # SSLRequireSSL AuthType Basic AuthName "Subversion Authorization Realm" AuthUserFile /var/www/htpasswd Require valid-user --------- End --------- Reload apache: # service httpd reload Reloading httpd: [ OK ] At this point, you should have a nice, working, browsable repository. You can test this by browsing to it at, say, http://localhost.localdomain/svn/repos (the path specified by the "Location" directive in your subversion.conf file) and you'll probaby see something relatively uninteresting like... Revision 0: / Powered by Subversion version 0.32.1 (r7497). 4) Now, you should try adding some files and seeing if it actually works. See the FAQ and the Subversion Book here. I've included my error message since this seems like an easy mistake (forgetting the -m flag to specify the log message for the commit). Import files into the archive. I use my Basic Authentication credentials from my AuthUserFile specified in /etc/httpd/conf.d/subversion.conf: $ cd /src/dir $ svn import . http://localhost.localdomain/svn/repos/ svn: No external editor available svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options. svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no 'editor-cmd' run-time configuration option was found. $ svn -m "initial import to svn" import . http://localhost.localdomain/svn/repos/ Authentication realm: Subversion Authorization Realm Password for 'chowell': Adding foo.php Adding foo.css Adding (bin) foo.ico Adding bar.php Adding functions.php Committed revision 1. --------- End --------- Now, when I browse to that directory in my browser, I see Revision 1: / bar.php foo.css foo.ico foo.php functions.php Powered by Subversion version 0.32.1 (r7497). --------- End --------- And the world is my oyster! 5) Checking out files This is really beyond the scope, but I thought I'd throw it in. Files can be checked out with either the `svn` command or with one of the graphical front-ends available. See the Subversion Web site for some options. JSVN and RapidSVN are the two I'm familiar with and each has its own quirks. I mostly prefer the command-line at this time. To check out a set of source files, change to the parent directory and check out the entire repository: $ cd ~/src $ svn co http://localhost.localdomain/svn/repos1 A repos1/foo.php A repos1/bar.php A repos1/foo.css A repos1/functions.php A repos1/foo.ico Checked out revision 1. After you make changes, you can commit your changes with: $ svn ci -m "Fixed bugs...hopefully more than I created with my fixes ;-)" foo.php chowell's password: Sending foo.php Transmitting file data . Committed revision 2. --------- End --------- And we're done! One last note, most diff'ing and merging tools integrate Subversion support without even trying to (on Linux, at least) since they support URL's for locations. Thus, they are indifferent to whether your compared source files are stored at file:// or http:// . KDiff, in particular, works just fine this way.