Subversion is a popular SCM (source code management) application. Subversion allows you to keep various versions of your web development files. This way, if you make a mistake or decide you want to go back to an earlier version of your site, you can simply find the desired version.
Version control and SCM is very complex topic, but we will try to focus on the simple tasks of installing Subversion using Apache for hosting your files via HTTP. The importance of having HTTP hosting for Subversion is so that you can use the Subversion integration in the Eclipse integrated development environment (IDE).
The key to a successful Subversion installation is to use the version with the proper binaries (already compiled files) for the Apache server in your WampServer installation. At the time of this writing, WampServer includes Apache version 2.2.11, which can use Subversion version 1.6.6. Download Subversion from http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=8100.
The default installation location in the Subversion installer is C:\Program Files\Subversion\. However, since we will be using Subversion with our WampServer installation, change the installation directory to c:\wamp\svn. (“svn” is the common short-hand for Subversion.) Other than this change, you can use the other installation defaults.
Subversion stores its data is sets of files called repositories. You must have at least one repository to use Subversion. Most of the Subversion application files are command line utilities. However, we will be insulated from most of these utilities after completing this configuration by using Subversion from Eclipse. The structure of your repository is very important. To that end, we will be using the “standard” repository structure recommended in the Subversion “Red Book”, which is the canonical reference for Subversion:
.../project_name/ trunk/ tags/ branches/
In this structure, project_name represents the so-called project root directory, which is the top-most directory for files related to project_name. The trunk sub-directory is where the main code and files for your site or project is stored. You can think of the trunk as the “main branch” of a tree. The tags sub-directory contains “snapshots” of your files from particular points in time. For example, when you release the first version of your application or web site, you’ll probably want to create a version 1.0 snapshot or tag. In general, you never change files in the tags directory; they are simply reference points in your files. Finally, the branches directory is used for creating named branches of your main code (i.e., from the trunk). Typically, branches are used when you need to do parallel development, which means that two development activities on the same set of code (files) is taking place simultaneously. Usually, at some point, you merge the code from one (or more) branch back into the trunk before continuing development.
We’ll use a sub-directory of c:\wamp\svn called repos as the home for our repositories (e.g., c:\wamp\svn\repos). Often, this directory is referred to as the repository “root” directory. To do this, open a Windows Command Prompt: Start –> Programs –> Accessories –> Command Prompt and change to the c:\wamp\svn directory:
Now create a new subdirectory named repos:
Change to the the repos directory (cd repos) and create a directory with the name of the project. In this example, I’m developing a simple inventory system for a church teachers’ workroom, so I’ll name my project workroom for simplicity:
Now, we actually create the Subversion repository for this project using the svnadmin command:
svnadmin create c:\wamp\svn\repos\workroom
With our Subversion repository created, we turn to actually configuring Apache to be the “front end” for Subversion by providing the HTTP hosting for Subversion, so that we can access our repository directly from Eclipse.
First, we need to copy the Subversion Apache modules from our Subversion installation folder to the Apache installation folder. To do this, copy mod_authz_svn.so and mod_dav_svn.so from c:\wamp\svn\httpd to c:\wamp\bin\apache\Apache2.2.11\modules.
Next, the Apache configuration file (httpd.conf) is updated to load these modules. Open c:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf with a plain text editor, such as Notepad. In httpd.conf, look for the lines that start with LoadModule and add the following lines in this section and save the file:
LoadModule dav_module modules/mod_dav.so LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so
Next, we set our Subversion configuration parameters in the Apache confiugration file. At the end (bottom) of httpd.conf add the following lines and save the file:
<Location /svn/> DAV svn #specify the root directory for repositories SVNParentPath c:/wamp/svn/repos/ #list repositories SVNListParentPath on #access control policy #authentication file AuthzSVNAccessFile conf/apachesvnauth #type of authentication AuthType Basic #the name of the authentication AuthName "Subversion repository" #file with user passwords values AuthUserFile conf/apachesvnpasswd #only allow authorized users to log in Require valid-user </Location>
The first line (“<Location /svn/>”) defines the “alias” that Apache will use for the Subversion repositories. This means that by entering http://localhost/svn/, you'll be able to access your Subversion repositories. The SVNListParent Path on directive tells Apache to list the names of the repositories when you browse to http://localhost/svn/.
Note on the SVNParentPath line that the forward slash (/) is used, rather than the back slash (\) normally used in Windows. The reason is that Apache uses the Unix directory separator, which is the forward slash.
Also, you’ll notice that this configuration includes two additional files: apachesvnauth and apachesvnpasswd. These are the permissions configuration and user ID/password list files, respectively. To create the apachesvnpasswd file, return to the Windows Command Prompt from earlier and change to the c:\wamp\bin\apache\Apache2.2.11\conf directory and execute this command:
htpasswd -cm apachesvnpasswd username
where username is the user ID that you want to use with Subversion. You’ll be prompted to enter a password for this account. The ‘m’ option means that the password will be encrypted using the MD5 algorithm. (If you want to bypass the encryption and store the password in plain text, just leave off the ‘m’ in the command.)
To create the apachesvnauth permissions file, open an empty file in a text editor, such as Notepad and enter the following lines:
[workflow:/] username = rw * = r
Replace workflow by the name of the repository that you created earlier and substitute your user ID for username. This configuration means that your user ID has read and write permissions to all files in the project and ‘* = r’ allows any user to view the files (i.e., read-only access) in the project. Save this file as apachesvnauth. (You can also define groups and restrict access to specific sub-directories of a repository, but that is beyond the scope of this tutorial.)
Now, stop and restart the Apache web server (or the entire WampServer system, if desired). You can do this by clicking (with left mouse button) on the WampServer icon in the system tray and choose ‘Restart All Services’ from the menu.