Setting up Subversion on Amazon EC2 for free

Remote backups are crazily important for Colin and I with our nomadic lifestyle. We consider ourselves very lucky that we haven’t had our laptops stolen or destroyed in 5 years of travel. We take precautions: we lock our doors, keep our laptops out of sight, and try to give off an air of “thrifty backpackers” while actually carrying around $6,000 worth of electronics. But if it should ever happen, we could be up and working again within 24 hours thanks to offsite backups.

I use Dropbox for large files and Google Drive for documents (both free to a point), and for code I use offsite version control software. There are free hosting services for Git… but after working with it on several projects over many years I still don’t fully understand Git and consistently screw up commits. I am much more comfortable with older, simpler Subversion. But there are no free or even reasonably-priced hosting options for svn projects unless you make them open source.

However, Amazon is offering free linux EC2 servers with 30gb ssd hard drive space. For a relatively small project like Rebuild with only a couple contributors and few branches, that’s more than enough, and the equivalent hosted option costs $50/month or more. The trick is configuring it. This took me a few hours, some false starts and useful tutorials. You do need to be familiar with Linux. I documented the process for my own uses, but here it is for you:

Creating an EC2 instance and SSHing in

Create a new EC2 instance
They won’t charge you unless you go beyond their free tier
I chose to put mine in Oregon (us-west-2)
Check “only free” and pick a freebie amazon linux ami
I used amzn-ami-hvm-2014.09.1.x86_64-ebs (ami-b5a7ea85)
Next page, choose max free (30gb) ssd
Next page, open HTTP port to all (0.0.0.0) – SSH is already open by default
Complete and launch your instance

Create a new key pair when prompted and download the .PPK file from amazon.
Visit the EC2 dashboard, instance should be Running and status checks 2/2
Record your instance IP (YOUR_INSTANCE_IP)
Download Putty
SSH into your instance using the PPK from amazon (guide)
Default amazon AMI SSH username is ec2-user, no password
ec2-user@YOUR_INSTANCE_IP

You’re in! Putty hint: right-click to paste clipboard contents.

Installing software

Update pre-installed software:
# sudo yum update -y

Visit the public ip in your browser: http://YOUR_INSTANCE_IP
should see Amazon Linux AMI Test Page if Apache is installed and running

If Apache is not installed (guide):
# sudo yum groupinstall -y "Web Server" "MySQL Database" "PHP Support"
# sudo yum install -y php-mysql
# sudo service httpd start

Install subversion and mod_dav_svn (should see a long list of all changes):
# sudo yum –y install mod_dav_svn
# sudo yum –y install subversion

Edit the Apache configuration file for subversion:
# sudo vi /etc/httpd/conf.d/subversion.conf
Replace any subversion.conf content with:

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so
<Location /repos>
   DAV svn
   SVNParentPath /var/www/svn
   # Limit write permission to list of valid users.
   AuthType Basic
   AuthName "Authorization Realm"
   AuthUserFile /var/www/svn-auth/passwd
   AuthzSVNAccessFile  /var/www/svn-auth/access
   Require valid-user
</Location>

Create the directory which will contain the subversion repository:
# sudo mkdir /var/www/svn

Create the directory which will contain the permissions files.
# sudo mkdir /var/www/svn-auth

Create the permission file:
# sudo vi /var/www/svn-auth/access
And fill it with (replace sarah, colin, guest with your usernames):

[/]
sarah = rw
colin = rw
guest = rw

Create and add to the password file (use -c the first time to create)
# sudo htpasswd -cb /var/www/svn-auth/passwd sarah SARAHSPASSWORD
# sudo htpasswd -b /var/www/svn-auth/passwd colin COLINSPASSWORD
# sudo htpasswd -b /var/www/svn-auth/passwd guest GUESTSPASSWORD

Create a repository (REPONAME is the name of your repository eg rebuild):
# cd /var/www/svn
# sudo svnadmin create REPONAME

Change files authorization (again after creating new repos too):
# sudo chown -R apache.apache /var/www/svn /var/www/svn-auth
# sudo chmod 600 /var/www/svn-auth/access /var/www/svn-auth/passwd

Start apache web server:
# sudo service httpd restart
Will complain about determining domain and using 127.0.0.1, that’s ok

To make sure apache always starts on boot:
# sudo chkconfig httpd on
# sudo chkconfig --list
Should show 2:on 3:on 4:on 5:on for httpd

Verify the subversion repo by opening in a browser:
http://YOUR_INSTANCE_IP/repos/REPONAME

You’re done! Connect via Tortoise or your fav svn client using the url above.

Other operations

To copy from an older repo including revisions:
# sudo svnadmin dump /var/www/svn/REPONAME > /tmp/REPONAME.svn
(copy the file to the new server then)
# sudo svnadmin load /var/www/svn/REPONAME < /tmp/REPONAME.svn

To connect a backup mirror on another (non-free) EC2 server with the same setup (guide)
First make revisions editable in the mirror repo:
# sudo echo '#!/bin/sh' > /var/www/svn/REPONAME/hooks/pre-revprop-change
# sudo chmod 755 /var/www/svn/REPONAME/hooks/pre-revprop-change
Then initialize the mirror from the old one:
# sudo svnsync init file:///var/www/svn/REPONAME http://YOUR_INSTANCE_IP/repos/REPONAME
Should see "Copied properties for revision 0."
Then copy the data including all revisions:
# sudo svnsync sync file:///var/www/svn/REPONAME
Can use this to make nightly backups to another server

Share

20 thoughts on “Setting up Subversion on Amazon EC2 for free

  1. You have a typo:

    # sudo yum –y install mod_dav_svn
    # sudo yum –y install subversion

    should be:

    # sudo yum install -y mod_dav_svn
    # sudo yum install -y subversion

    1. The -y options set the installation to run without confirmation messages like:

      # is this ok [Y/n]:

    2. I agree if you put -y before the install it just verifies the package location -y has to be after the yum operation or after the package

  2. Can any one help me with the below issue??

    When im restarting the Apache, Im running in to below issue
    sudo service httpd restart

    Stopping httpd: [FAILED]
    Starting httpd: httpd: Syntax error on line 353 of /etc/httpd/conf/httpd.conf: Syntax error on line 2 of /etc/httpd/conf.d/subversion.conf: Cannot load modules/mod_dav_svn.so into server: /etc/httpd/modules/mod_dav_svn.so: cannot open shared object file: No such file or directory

    Here are my subversion.conf file content :

    LoadModule dav_svn_module modules/mod_dav_svn.so
    LoadModule authz_svn_module modules/mod_authz_svn.so

    DAV svn
    SVNParentPath /var/www/svn
    # Limit write permission to list of valid users.
    AuthType Basic
    AuthName “Authorization Realm”
    AuthUserFile /var/www/svn-auth/passwd
    AuthzSVNAccessFile /var/www/svn-auth/access
    Require valid-user

  3. Can any one help me with the below issue??

    When I am verify the subversion repo by opening in a browser the following error message appears:

    Could not open the requested SVN filesystem

  4. When you try to import you may get below error
    svn import /tmp/xx http://localhost/repos/xx -m “initial”
    svn: E175002: Server sent unexpected return value (500 Internal Server Error)

    In the httpd error_log if you see this error use the below command to set the permission to apache
    [:error] [pid 3298] [client ::1:42043] Can’t open file ‘/var/www/svn/xx/db/txn-current-lock’: Permission denied [500, #13]

    sudo setsebool -P httpd_unified=1

  5. I get the following error when i authenticate correctly with the user name and password

    Forbidden

    You don’t have permission to access /repos/vikram on this server.

    1. Make sure you did the right edits on the permission file:
      # sudo vi /var/www/svn-auth/access

      (to save press ESC and type :w
      to quit, press ESC and type :q!
      yes, the : is part of the command e.g. :q!)

      also, make sure, you created and add to the password file and changed files authorization, restarted apache:

      Create and add to the password file (use -c the first time to create)
      # sudo htpasswd -cb /var/www/svn-auth/passwd sarah SARAHSPASSWORD
      # sudo htpasswd -b /var/www/svn-auth/passwd colin COLINSPASSWORD
      # sudo htpasswd -b /var/www/svn-auth/passwd guest GUESTSPASSWORD

      Change files authorization (again after creating new repos too):
      # sudo chown -R apache.apache /var/www/svn /var/www/svn-auth
      # sudo chmod 600 /var/www/svn-auth/access /var/www/svn-auth/passwd

      ReStart apache web server:
      # sudo service httpd restart

      in my case, most common mistakes are editing and not saving with vi and forgetting to restart apache ;)

  6. Following the steps above I get the following error. Can anyone help me on this:

    Forbidden

    You don’t have permission to access /repos/codebase1 on this server.

  7. comment this lines
    #LoadModule dav_svn_module modules/mod_dav_svn.so
    #LoadModule authz_svn_module modules/mod_authz_svn.so
    in /etc/httpd/conf.d/subversion.conf

  8. Set up went well and able to access with URL.
    how to connect this form svn client in remote system? OR how to integrate with IDE?
    Can you please any one guide on that bit?

    Thanks in advance.

  9. Good blog post, all the piece of codes working fine. I could successfully setup subversion on Amazon EC 2. Thanks for writing this great blog.

  10. Hello! i’m having this error, can you help me please? and thanks in advance!

    This XML file does not appear to have any style information associated with it. The document tree is shown below.

    Could not open the requested SVN filesystem

  11. Лично я сейчас же запишу ваш rss, поскольку
    я не могу найти ваш email hyperlink или
    e-newsletter. Можно ли попросить ваши контакты?
    Будьте добры, разрешите мне связаться с вами так, чтобы
    я мог бы подписаться. Благодарю.

Leave a Reply

Your email address will not be published.