So, I recently started a new job as Lead Developer on carsireland.ie and one of the first things I was tasked with was moving the codebase from a simple PC running Linux to the cloud, so that it could be accessed remotely, outside the office. Now, while I do prefer Git, SVN is still reasonably popular, especially with websites older than a few years, hence the CTO wanted to stick with it, for the time being at least! Needless to say, most of the following is best done as root, or at least with sudo privileges. Also, this is done on Ubuntu, hence the use of apt-get
.
1. Setting up Apache for HTTPS
Apache was already running on the server, but it had to be enabled for HTTPS. Firstly You need to generate self-signed SSL certificates. You’ll be asked for a passphrase; enter one and note it down:
1 2 3 | openssl genrsa -des3 -out server.key 2048 openssl req -new -key server.key -out server.csr openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt |
Move the certificates to somewhere that Apache expects to find it:
1 2 | cp server.crt /etc/ssl/certs cp server.key /etc/ssl/private |
Enable SSL for Apache
1 2 3 4 5 | a2enmod ssl a2ensite default-ssl /etc/init.d/apache2 stop; sleep 2; /etc/init.d/apache2 start # this last step is how I restart Apache. # I don't trust the 'restart' option. There's probably other/better ways of doing this |
2. SVN
Install SVN and it’s Apache module
1 | apt-get install subversion libapache2-svn |
Create a new folder for the code (we’ll call the folder ‘svn’):
1 | mkdir /home/svn |
Create the repository:
1 | svnadmin create /home/svn |
Tell Apache about the repository:
1 | nano /etc/apache2/sites-available/default-ssl |
This opens up the pretty simple nano editor. At the bottom of the file, before the final <VirtualHost>
, add:
1 2 3 4 5 6 7 8 | <Location /svn> DAV svn SVNPath /home/svn AuthType Basic AuthName "Your repository name" AuthUserFile /etc/subversion/passwd Require valid-user </Location> |
You may need to enable your SSL site, so if the files /etc/apache2/sites-enabled/000-default-ssl
or /etc/apache2/sites-enabled/default-ssl
don’t exist, do:
1 | ln -s /etc/apache2/sites-available/default-ssl /etc/apache2/sites-enabled/000-default-ssl |
For Apache to be able to read/write to the repository, we need to change it’s owner to www-data:
1 | chown -R www-data:www-data /home/svn |
Next, we need to add some login details for users, i.e. developers (you’ll be asked to enter a password):
1 2 3 | htpasswd -c /etc/subversion/passwd user_name # user_name should correspond with the username of some one you want to have access to the repository. # The password entered can be different from their normal login password and is used to access the repository at all times. |
For subsequent users, drop the -c
flag above.
Restart Apache (however you want to do it). Following from above:
1 | /etc/init.d/apache2; sleep 2; /etc/init.d/apache2 start |
You should now be able to view the initial empty repository at http://server.locaton/svn
where ‘server.location’ is either an IP address or a domain, depending on how you’ve set-up the server.
If you have an SVN dump of your repository and you want to load it into the new one, you can simply do:
1 | svnadmin load --force-uid /home/svn < dumpfile |
At this point, your SVN server should be up and running and ready to take commits. You may need to play around with the permissions of your /home/svn
directories, making certain ones executable/writeable to Apache. If I’ve left anything else out, please let me know in the comments.
No Comments
Leave a reply
You must be logged in to post a comment.