This is a  summary of how to set up a new svn repository that you can access through apache when your server is configured with cPanel. This is not a tutorial on installing cPanel and Subversion.  The assumption is that you already have subversion installed on your cPanel managed server.

1) Set up an account where you want to host your subversion repositories, perhaps use a domain like subversion.mywebsite.com

2) SSH into your new account and create a directory that will contain all your subversion repositories. For example, you might have a path like /home/<username>/subversion where <username> is the username you used to log into your account.

3) Set up a subversion repository by changing directories into your subversion directory you just created and issuing the following commands.

cd /home/username/subversion
svnadmin create myproject
sudo chgrp -R nobody myproject
sudo chmod -R g+w myproject

Note that we changed the group to “nobody” which is the user that apache runs as. You need to do this so that when you access the repository through apache, apache has permission to write files to your repository. By default, cPanel runs apache with the user “nobody” but not always. So, just be sure that you set the correct group name for your repository.

4) Next you need to tell apache about your new subversion repository. To do that, log into your cPanel WHM account and go to Service Configuration -> Apache Configuration -> Include Editor and edit the Pre VirtualHost Include file. Enter in a block like this:

<Location /path/to/repository>
DAV svn
SVNPath /absolute/path/to/repository
AuthType Basic
AuthName “Subversion Repository”
AuthUserFile /absolute/path/to/password/file.txt
Require valid-user
</Location>

The first path in the block above is /path/to/repository in the Location tag. This is the path you want to use when accessing the repository through Apache.  For example, if you wanted to access your repository at http://subversion.mywebsite.com/myproject then you would simply write /myproject as the path in the Location tag.

The second path is the SVNPath which is the absolute path to your subversion repository. So in our example you would use /home/username/subversion/myproject

The third path is the absolute path to you htpasswd file. We haven’t created this yet but we will in the next step. You may choose to put this file in any directory you wish perhaps at /home/username/svnpasswords.txt This is the file that will contain the usernames and passwords for accessing your Subversion repository through Apache.

When you are all finished click the button to restart Apache.

5) Now we need to create the htpasswd file. Change directories into the directory where you want to store your password file and issue this command:

htpasswd -c svnpasswords.txt

If you want more than one user, run the same command again but leave off the -c. If you don’t leave off the -c then a new password file will be created and all your previous entries will be lost.

6) Finally, you will want to create the normal trunk, tags, and branches folders in your repository. You can issue these commands from your development machine if you like since you are now able to access your repository through apache.

svn mkdir http://subversion.mywebsite.com/myproject/trunk -m “creating trunk”
svn mkdir http://subversion.mywebsite.com/myproject/tags -m “creating tags”
svn mkdir http://subversion.mywebsite.com/myproject/branches -m “creating branches”

Now you have your repository all set up and ready to receive your source code. So, normally speaking you would checkout out your trunk, add some files, and commit your initial set of files to the repository.