Pre-Conditions
This tutorial is written for Apache 2.2.22 and Subversion 1.6.17. This document will not be updated.
Install packages
As a first step we need to install all required packages.
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install subversion
sudo apt-get install libapache2-svn
Include Apache modules
Here we activate some required apache modules
sudo a2enmod dav
sudo a2enmod dav_svn
sudo a2enmod ssl
Create directory structure
Next we create the directory structure.
- public: Root directory of the virtual host container
- repo: Directory that contains all subversion repositories
- auth: Directory that contains all htpasswd files
- ssl: Directory that contains the ssl cert and key
sudo mkdir /var/www/svn.yourdomain.com
sudo mkdir /var/www/svn.yourdomain.com/public
sudo mkdir /var/www/svn.yourdomain.com/repo
sudo mkdir /var/www/svn.yourdomain.com/auth
sudo mkdir /var/www/svn.yourdomain.com/ssl
Create repository
Next we create a first repository
sudo svnadmin create /var/www/svn.yourdomain.com/repo/test-project
Create group
Then we create the necessary groups
sudo groupadd subversion
sudo addgroup you subversion
Create credentials for login
As we authenticate with http basic method we create a password file
sudo htpasswd -c /var/www/svn.yourdomain.com/auth/test_project.passwd you
Create SSL certificate
When requesting a new certificate, it is possible to specify with -days how long the certificate will remain valid. In the example below it's 365 days. This will create both, the self-signed SSL certificate and the server key that protects it.
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /var/www/svn.yourdomain.com/ssl/ssl.key -out /var/www/svn.yourdomain.com/ssl/ssl.crt
After that a prompt appears that will ask us some questions.
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Your Inc
Organizational Unit Name (eg, section) []:Dept of something
Common Name (e.g. server FQDN or YOUR name) []:svn.yourdomain.com
Email Address []:webmaster@yourdomain.com
Create the virtualhost
Next we create a virtualhost entry: /etc/apache2/sites-available/svn.yourdomain.com.conf
<VirtualHost *:443>
ServerName svn.yourdomain.com
ServerAdmin webmaster@yourdomain.com
ErrorLog /var/log/apache2/svn.yourdomain.com.err.log
CustomLog /var/log/apache2/svn.yourdomain.com.acc.log combined
DocumentRoot /var/www/svn.yourdomain.com/public
<Directory "/var/www/svn.yourdomain.com/public">
Order allow,deny
Allow from all
</Directory>
SSLEngine on
SSLCertificateFile /var/www/svn.yourdomain.com/ssl/ssl.crt
SSLCertificateKeyFile /var/www/svn.yourdomain.com/ssl/ssl.key
# Test project
<Location /svn/test-project>
DAV svn
SVNPath /var/www/svn.yourdomain.com/repo/test-project
AuthType Basic
AuthName "Test-Project Server Repo"
AuthUserFile /var/www/svn.yourdomain.com/auth/test-project.pwd
Require valid-user
</Location>
</VirtualHost>
Activate the virtualhost directive
Apache looks for files in /etc/apache2/sites-enabled. So you need to create a symlink.
cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/svn.yourdomain.com.conf .
Set the right permissions
It is important that you set the right permissions so that apache can write data in to the svn repository and can also read the htpasswd file.
sudo chown -R www-data:subversion /var/www/svn.yourdomain.com
Reload Apache
service apache2 restart
Test Url
You should now be able to connect to https://svn.yourdomain.com/svn/test-project
No comments:
Post a Comment