
Configuring Subversion and Apache on Ubuntu for virtual hosts with (SSL) Secure Socket Layer is fairly straight forward but if you’ve installed Apache 2 with synaptic you will find that some of the tools have different names or are completely missing, here I will walk through each step of the installation and configuration of each part explaining what does what and the various options that you can put in place to limit access. This way we will have access to the subversion repository at https://svn.domain.com.
Once you have followed the tutorial I would recommend using RapidSvn and Meld or KDiff as they are two of the tool I regularly use with my repositories. RapidSvn is a GUI subversion tools so you can commit etc. It doesn’t have a visual diff tool which is unfortunate but Meld is the best visual tool I have found for Gnome, these in the Ubuntu repositories or if you are using Kbuntu you can use KDiff, you can install these two tools easily using synaptic or apt-get.In this tutorial we will cover installing Apache2, Subversion and configuring the SSL creation of the required certificate using the apache tools and the configuration of the Virtual Host so you can access the repository via a subdomain. Finally we will set the access so you can controll who will have acces to your repositories.With 11 steps you will have a subversion respository up an running with SSL and Virtual hosts and each step explains what is happening so you can easily understand the full process
1. Install Apache
In the terminal type:
sudo apt-get install apache2 apache2.2-common apache2-utils
This installs the apache 2 server common modules and utilities
2. Install Subversion
In the terminal type:
sudo apt-get install subversion subversion-tools
3. Install Apache Subversion Modules
In the terminal :
sudo apt-get install libapache2-svn
4. Restart Apache
In the terminal type:
sudo apache2ctl restart
5. Enable SSL Apache Module
In the terminal type:
sudo a2enmod ssl
6. Enable Apache to listen to the correct port for ssl (443)
In the terminal type:
sudo gedit /etc/apache2/ports.conf
Add the line: Listen 443
7. Create a certificate for SSL use.
Unfortunately apache is missing the tool (apache2-ssl-certificate) required to create the certificate but this can be easily downloaded from apache2-ssl.tar.gz , download this file and extract the package. There are two files ssleay.cnf and apache2-ssl-certificate. In the terminal navigate to the directory two files have been extracted and type:
sudo mkdir /etc/apache2/sslsudo cp ./ssleany.cnf /etc/apache2/ssl/sudo cp ./apache2-ssl-certificate /usr/sbin/
Now create your certificate with and follow the instructions
sudo apache2-ssl-certificate
8. Create a Subversion repository
Here make a directory where you want to store one or more subversion repositories, in this example I’m using /srv/svn/repos/
sudo mkdir /srv
sudo mkdir /srv/svn
sudo mkdir /srv/svn/repos
Now make the repository directory accessible to apache (www-data)
chown www-data:www-data /srv/svn/repos
Now we will make the first repository using the super user www-data
cd /srv/svn/repos
su -u www-data -s
svnadmin create projectname
We now have our first subversion repository remember when creating other repositories always use the su www-data to ensure apache can access the repository.
9. Creating the virtual host
Create the virtul host file for Apache
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/svn.domain.comsudo gedit /etc/apache2/sites-available/svn.domain.com
Copy and paste the following code edit the domain name and repository path if different:
NameVirtualHost *:443
<VirtualHost *:443>
ServerAdmin yourname@domain.com
ServerName svn.domain.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
SSLProtocol all
SSLCipherSuite HIGH:MEDIUM
<Location />
Order allow,deny
Allow from all
DAV svn
SVNPath /srv/svn/repos/projectname
AuthType Basic
AuthName "domain.com Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg.
LogLevel warn CustomLog /var/log/apache2/access.log combined
</VirtualHost>
If you have many projects that you will be using the repository change
SVNPath /srv/svn/repos/project
to
SVNParentPath /srv/svn/repos
10. Create user(s) to access subversion repository
sudo htpasswd -c /etc/apache2/dav_svn.passwd username
to add more users use -m (the -c creates a new file)
sudo htpasswd -m /etc/apache2/dav_svn.passwd username2
11. Restart Apache and test
sudo /etc/init.d/apache2 restart
Now test your repostory with https://svn.domain.com and enjoy, if I’ve missed steps out please let me know in the comments.