Learn to use Subversion as your version control system in Linux. Vincent Danen shows you how to connect to a Subversion repository with an Apache 2 Web server.
Subversion is a version control system similar to CVS in many respects, but one major differing component is that, unlike CVS, there are multiple means of accessing your repositories. One of the more popular, and flexible, ways of connecting to a subversion repository is through the use of the Apache 2 Web server.
Using Apache rather than, or in conjunction with, the svnserve program allows for more flexible access to a repository in that you can have fine-grained access controls over who sees what, who can change what, and so forth. However, to enable the use of Apache as a front-end to the repository, you need to configure it.
The first step is to install subversion and the mod_dav_svn module for Apache 2. This can be done either through building subversion from source, or by installing a binary package from your Linux vendor; most vendors ship with subversion. Failing that, you can download binaries for different platforms off the subversion Web site.
Once they are installed, if you haven't first created a repository, do so using:
# mkdir /usr/local/subversion
# chown svn:svn /usr/local/subversion
# chmod g+s /usr/local/subversion
# svnadmin create /usr/local/subversion/repos
This does a few things: first you create your subversion repository and make it owned by the user svn and group svn (if these don't exist, make sure you create them). Then you set the sgid bit on the directory so that all files created will be owned by the group svn. This will allow for multiple access methods to the repository, and you won't have to worry about permissions. Finally, svnadmin is used to create the repository.
Next, edit your Apache configuration files and add:
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
<LimitExcept GET PROPFIND OPTIONS REPORT>
AuthName "Subversion Repository"
Because subversion uses WebDAV, you will need the mod_dav Apache module loaded as well, and it needs to be loaded before mod_dav_svn. The configuration here will make any requests to http://yourhost/svn point to the subversion repository. You also have access controls in place that allow viewing/reading access to everyone, but you restrict everything else such as writing, moving, copying, etc. You also point to a password file that contains a list of usernames and passwords that are to be used to authenticate any requests to change the repository.
That file, /etc/svn-auth-file, can be created using htpasswd:
# htpasswd -m -c /etc/svn-auth-file joe
You will be prompted for a password for joe; enter it twice. To add other users, omit the -c option as that tells htpasswd to create a new file. Once this is done, restart Apache and connect to your server, and you should be able to browse your repository. (If you haven't imported or added anything to the repository, you may need to do that before you see anything of interest.)
Finally, be sure to add the Web server as a user (usually Apache or nobody) to the svn group that you created, otherwise the Apache service will not be able to commit changes to the repository on your behalf.