Creating an EC2 instance and connecting via SSH

Create a new EC2 instance (free, unless you go beyond the free tier)
Choose an AMI: check “Free tier only” and pick the Amazon Linux AMI
Next (Choose an Instance Type): choose General purpose t2.microFree tier eligible (EBS only)
Next (Configure Instance Details): leave everything as is unless you need some changes e.g. subnet
Next (Add Storage): change Size (GiB) to up to 30GB
Next (Tag Instance): e.g. Key = Name, Value = MySVN or Key = Owner, Value = Yatko – learn more about tagging
Next (Configure Security Group): SSH should be already open, below click Add Rule and select HTTP on port 80, Anywhere (0.0.0.0/0)
Review and Launch

Create a new key pair when prompted and download the .PPK file from amazon, save it in a safe place!
Visit the EC2 dashboard, instance should be Running and status checks 2/2 checks
Record your instance Public IP (and/or Public DNS)
if Mac/Linux, open a Terminal window
SSH into your instance:

locate the path where your .PPK file from amazon was saved e.g. /Documents/YOUR_PPK-FILE_PATH/mysvn.pem.txt
# cd /Documents/YOUR_PPK-FILE_PATH/
# ssh -i mysvn.pem.txt ec2-user@YOUR_EC2_PUBLIC-IP

If you encounter “WARNING: UNPROTECTED PRIVATE KEY FILE”, try to chmod your keypair to 600:
# chmod 600 mysvn.pem.txt

In case you run into more issues, read/ask here.

if Windows (skip next 4 lines for Mac/Linux), 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_EC2_PUBLIC-IP
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_EC2_PUBLIC-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 install -y mod_dav_svn
# sudo sudo yum install -y subversion

or:
# sudo yum install mod_dav_svn 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):

[/]
admin = rw
user1 = rw
guest = r

Create and add to the password file (use -c the first time to create)
# sudo htpasswd -cb /var/www/svn-auth/passwd admin ADMIN_PASSWORD
# sudo htpasswd -b /var/www/svn-auth/passwd user1 USER1_PASSWORD
# sudo htpasswd -b /var/www/svn-auth/passwd guest GUEST_PASSWORD

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

Restart apache web server:
# sudo service httpd restart
May 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_EC2_PUBLIC-IP/repos/REPONAME

You’re done! Connect via 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

Advertisements