Installing and setting up Subversion on a WHM/Cpanel machine

This post is desired to be a 101 on installing and setting up Subversion on a WHM/Cpanel machine.

Notes:
1. The following was tested using WHM version 11.30.4 (build 6), installed in CentOS 5.7
2. The following reference will be used:
example = referring to the account name of a cPanel account set up in WHM
example.com = the domain for which the example account was set up for
3. You will need to get dirty with the terminal using SSH access
4. The setup is going to use Apache’s mod_dav for authentication

Installing mod_dav (if needed)

First, check to see if mod_dav isn’t already installed on your system by running the following command in the terminal:

root@machine [~]# /sbin/service httpd -M | grep dav

If mod_dav is already installed, it will return:

dav_module (static)
dav_fs_module (static)

If not, you will have to rerun EasyApache (EasyApache is a script used by WHM installations to configure Apache). You can do this by clicking on the EasyApache (Apache Update) link in the WHM menu. Select the most suitable profile to load based on what you are using the server for (if this is not a fresh server, it is better to read the EasyApache documentation before proceeding so that you don’t lose prior configurations). When you reach step 6 (Exhaustive Options List) be sure to check DavFS and Dav in the Apache Built-in Modules list. Save and build.
Note: Running EasyApache will shut down your webserver for about five minutes.

Install Subversion

In order to properly configure it, Subversion needs to be compiled from its sources. First, go to http://subversion.apache.org/download/#recommended-release and copy the link pointing to the .tar.gz archive (in my case, http://subversion.tigris.org/downloads/subversion-1.6.17.tar.gz). Now, download the source and unpack it:

root@machine [~]# cd /usr/local/src/
root@machine [/usr/local/src]# wget http://subversion.tigris.org/downloads/subversion-1.6.17.tar.gz
root@machine [/usr/local/src]# tar -xvf subversion-1.6.17.tar.gz

Before compiling Subversion, SQLite needs to be copied to the sources. Go to http://www.sqlite.org/download.html and get the link for the latest tarball. In my case, this is http://www.sqlite.org/sqlite-autoconf-3070800.tar.gz:

root@machine [/usr/local/src]# wget http://www.sqlite.org/sqlite-autoconf-3070800.tar.gz
root@machine [/usr/local/src]# tar -xvf sqlite-autoconf-3070800.tar.gz
root@machine [/usr/local/src]# cd subversion-1.6.17
root@machine [/usr/local/src/subversion-1.6.17]# mkdir sqlite-amalgamation
root@machine [/usr/local/src/subversion-1.6.17]# cp ../sqlite-autoconf-3070800/sqlite3.c ./sqlite-amalgamation/

Now, you need to configure Subversion in order to install it:

root@machine [/usr/local/src/subversion-1.6.17]# ./configure --with-apxs=/usr/local/apache/bin/apxs --with-apr=/home/cpeasyapache/src/httpd-2.2.19/srclib/apr --with-apr-util=/home/cpeasyapache/src/httpd-2.2.19/srclib/apr-util
root@machine [/usr/local/src/subversion-1.6.17]# make && make install

You may need to update your path to httpd, if you get the following error:

checking for APR... configure: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.
 
root@machine [/usr/local/src/subversion-1.6.17]# cd /home/cpeasyapache/src/
root@machine [/home/cpeasyapache/src]# ls -all

Look for httpd-*.*.** (where the stars are your script version) and update accordingly. cd back to the subversion directory and run the configure, make and make install commands again.

Subversion and Apache

Given you are using WHM and it uses EasyApache, you can’t just modify the Apache configuration to include the Subversion modules. Instead, you must use the Include Editor, which you can find by browsing to “Apache Configuration” in the WHM menu. There, you must use the Pre Main Include. Select the latest Apache version from the dropdown list and a textarea will appear. Add the following to it and click on “Update”:

LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so

Add Subversion users

Run the following command for every user you wish to add. You will be asked for passwords for each one:

root@machine [~]# /usr/local/apache/bin/htpasswd -cm /etc/svn-auth-conf username

Set up your first repository

I am assuming you are going to set up more than one repository on one domain, but this also applies to when you want just one repository.

First, you need to add a new virtual host for your repository:

root@machine [~]# cd /etc/httpd/conf/userdata/std/2/

If you get a “-bash: cd: /etc/httpd/conf/userdata/std/2/: No such file or directory” error, run these commands to create the folder:

root@machine [~]# mkdir /etc/httpd/conf/userdata
root@machine [~]# mkdir /etc/httpd/conf/userdata/std
root@machine [~]# mkdir /etc/httpd/conf/userdata/std/2

Now, add a folder for your domain:

root@machine [~]# mkdir /etc/httpd/conf/userdata/std/2/example
root@machine [~]# mkdir /etc/httpd/conf/userdata/std/2/example/example.com
root@machine [~]# cd /etc/httpd/conf/userdata/std/2/example/example.com

Next, you need to create the Subversion config file

root@machine [/etc/httpd/conf/userdata/std/2/example/example.com]# nano svn_custom.conf

Paste the following config and save the file. For every repository you wish to create, add another <location> block

<IfModule mod_dav_svn.c>
    #begin location
    <location /repo>
	DAV svn
	SVNPath /home/example/public_svn/repo/svn/
	AuthType Basic
	AuthName "SVN Repo"
	AuthUserFile /home/example/.svn.htpasswd
	Require valid-user
    </location>
    #end location
</IfModule>

Notice that we are using a folder called public_svn, outside the standard public_html folder. It is not recommended to add repositories in the same place as the public webserver files, because you are going to confuse Apache when you are going to try to access the repository through a local Subversion interface. Although you will be able to load the repository in your browser, you will get a “Repository moved permanently to ‘http://example.com/repo/’; please relocate” error when trying to access remotely. This happens because Apache doesn’t know how to respond to the request and gets confused on what it should return.

Now, create the actual repository files:

root@machine [~]# su example
example@machine [/root]# cd ~
example@machine [~]# mkdir public_svn
example@machine [~]# mkdir public_svn/repo
example@machine [~]# cd public_svn/repo
example@machine [~/public_svn/repo]# svnadmin create svn
example@machine [~/public_svn/repo]# chmod 775 -R svn
example@machine [~/public_svn/repo]# exit

Update the Apache configuration and you are all set up:

/scripts/ensure_vhost_includes --all-users

Go to http://example.com/repo to test your repository. It should ask for your user and password and then show you something like the following:

4 thoughts on “Installing and setting up Subversion on a WHM/Cpanel machine

  1. Thanks for the guide, I followed it, but I couldn’t access the svn page how you did in your screenshot, so I mapped a subdomain to the public_svn directory, and now Apache displays the files and folders, and as a result I can’t use svn. Any clues?

  2. Hi there,
    I’ve followed exactly what you described and each time when I access my repo and typing in user/pass I’m getting this:
    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.
    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

    Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8e-fips-rhel5 DAV/2 SVN/1.7.5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at my_website_url.com Port 80

    Any idea of how this could be resolved?

Leave a Reply to Mark Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">