Set up a SVN repository in AMAZON EC2 Ubuntu 14.04

Setting up a SVN Server for Small to Mid Size Project handling in Amazon EC2 Server with Operating System Ubuntu Server is an general process. But this is an non trivial process, when we look it from a programmer perspective. I have recently configured such one and hence making documentation of the same. May be it will help someone.

We assume that Amazon EC2 server is configured with SSH already.
Now, first we need to update the Existing Operating System with –

[html]
sudo apt-get update
sudo apt-get dist-upgrade
[/html]

Apache, PHP, MYsql Setup

We have to install and configure Apache as web server to make access of the SVN through HTTP.
[html]
sudo apt-get install apache2
[/html]
We have to enable rewrite module in apache.
[html]
sudo a2enmod rewrite
[/html]

We had to configure PHP to run with apache server.

[html]
apt-get install libapache2-mod-php5
[/html]
And then restart the Apache Server.
[html]
sudo service apache2 restart
[/html]

Now we had added the default user and group “www-data” to run apache server in ubuntu and made the required permission for those.

[html]
sudo adduser ubuntu www-data
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+rw /var/www
[/html]

Made another server Restart –
[html]
sudo /etc/init.d/apache2 restart
[/html]

We have installed mysql and php mysql driver to work the apache server seamlessly.

[html]
sudo apt-get install mysql-server
sudo apt-get install php5-mysql
sudo /etc/init.d/apache2 restart
[/html]

Subversion Setup

We have installed the subversion and related tools and apache svn module in our ec2 ubuntu instance.

[html]
sudo apt-get install subversion
sudo apt-get install libapache2-svn
sudo apt-get install subversion-tools
[/html]

We have created folder for SVN in /home folder. And made a test directory by using svnadmin tool. Also we have made necessary permission for the folders to the user “www-data”.

[html]
sudo mkdir /home/svn
sudo mkdir ~/test
sudo svnadmin create /home/svn/test
cd /home/svn
sudo chown -R www-data:www-data /home/svn
sudo chown -R www-data:www-data /home/svn
[/html]

Now as the new apache configuration has changed the folder structure and the enabled module related configuration are to be done in mods-enabled folder. For configuring svn, we needed to configure dav-svn.conf

[html]
cd /etc/apache2/
cd mods-enabled/
sudo nano /etc/apache2/mods-enabled/dav-svn.conf
[/html]

The changed configuration is –

[html]
<Location /repos>
DAV svn
SVNParentPath /home/svn
# Limit write permission to list of valid users.
AuthType Basic
AuthName "Authorization Realm"
AuthUserFile /home/svn/svn-auth/passwd
AuthzSVNAccessFile /home/svn/svn-auth/access
Require valid-user
</Location>
[/html]

Made another server Restart –
[html]
sudo service apache2 restart
[/html]

Rest of the works are relatively simple. We made 2 folders in SVN for our work –
[html]
sudo svnadmin create /home/svn/mobilesvn
sudo svnadmin create /home/svn/serversvn
[/html]

We had made the users to have access to the SVN folders.

[html]
sudo mkdir /home/svn/svn-auth/
sudo nano /home/svn/svn-auth/access

[/]
admin = rw
mobileuser = rw
serveruser = rw
[/html]

Now to create password for the users, we needed to install the apache2-utils utility.

[html]
sudo apt-get install apache2-utils
[/html]

We had created password –
[html]
sudo htpasswd -cb /home/svn/svn-auth/passwd admin ADMINPASS
sudo htpasswd -b /home/svn/svn-auth/passwd mobileuser MOBPASS
sudo htpasswd -b /home/svn/svn-auth/passwd serveruser SRVPASS
[/html]

Again, we have ensured the necessary permissions for the folders, so that they can not be accessed from external interface.

[html]
sudo chown -R www-data.www-data /home/svn /home/svn/svn-auth/
sudo chmod 600 /home/svn/svn-auth/access /home/svn/svn-auth/passwd
sudo service apache2 restart
[/html]

To ensure apache server at startup of the operating system, we made –
[html]
sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf apache2 on
sudo sysv-rc-conf apache2 –list
[/html]

So our server configuration is completed here.

Subversion Setup

Now to test on client side, to make everything is ok –

We have tested with our local box, which is connected to the internet –

[html]
svn checkout http://<<Elastic IP>>/svn/mobilesvn mobilesvn
gedit mobile-initial.txt
svn add mobile-initial.txt
svn commit -m ‘initial commit’
svn up

svn checkout http://<<Elastic IP>>/svn/serversvn serversvn
gedit server-initial.txt
svn add server-initial.txt
svn commit -m ‘initial commit’
svn up
[/html]

Now, when we accessed the above URLs, we have found the initial committed files in SVN.

So that is all.

If you find this article helpful, you can connect us in Google+ and Twitter.

1 thought on “Set up a SVN repository in AMAZON EC2 Ubuntu 14.04

  1. typo: about halfway down page you mention dav-svn.conf – the file should be dav_svn.conf

    ie. needs an underscore, not a hyphen

    thanks for tutorial!

Leave a Reply

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