Thursday, December 15, 2016

Simple steps to setup SVN server on Ubuntu

1. Install subversion and related modules using command,
sudo apt install subversion apache2 libapache2-svn apache2-utils
2. Create a directory for SVN root
mkdir /home/svn
3. Create a directory for your project repository 
mkdir /home/svn/MyProject
4. Using the following command create the repository
svnadmin create /home/svn/MyProject
5. Open the conf directory inside the repository directory and edit the svnserve.conf. Uncomment and change settings as,
general
password-db = passwd
anon-access = none # note this change; default will be read
6. Add user credentials in passwd file in same directory,
username = password
7. Start svn server using command,
svnserve -d -r /home/svn
 (Note: Use options --foreground and --config-file=filename, if required)

8. To start the svn server automatically on boot-up, create svnserve.conf inside the directory /etc/init and add below contents,
# svnserve - Subversion server
description    "Subversion Server"
start on (local-filesystems and net-device-up IFACE=lo and started udev-finish)
stop on runlevel [06]
#chdir /home/svn
#respawn
#respawn limit 2 3600
exec /usr/bin/svnserve -d -r /home/svn
 (Note: Use the commented options, if required)

9. Now the repository will be accessible via the url  
svn://hostname/MyProject
Optional,

10. To work with repository using SSH, install ssh server & start it; then use url
 svn+ssh://hostname/home/svn/MyProject
11. To  use HTTP edit the dav_svn.conf file in the directory /etc/apache2/mods-available. Add the following lines to it,
<Location /svn>
DAV svn
SVNParentPath /home/svn
SVNListParentPath On
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/subversion/passwd
Require valid-user
</Location>
12. Create a user group subversion using command,
sudo addgroup subversion
13. Add www-data to subversion(group) using command,
sudo adduser www-data subversion
14. Change ownership and permissions for the repository using below commands,
sudo chown -R www-data:www-data /home/svn/MyProject
sudo chmod -R g+rws /home/svn/MyProject
14. Restart apache server, using command,
service apache2 restart
15. Add SVN user credentials using command
 sudo htpasswd -c /etc/subversion/passwd user-name
16. Now the repository will be accessible via the url http://hostname/svn/MyProject

17. To use HTTPS configure the apache for SSL. Then the repository will be accessible via the url https://hostname/svn/MyProject

Note:-

1. To test repository access; use the command to checkout,
cd /home/Working-Directory
svn co http://hostname/svn/MyProject
or
svn co https://hostname/svn/MyProject
or
svn co svn://hostname/MyProject
or
svn co svn+ssh://hostname/home/svn/MyProject
2.a. To setup for HTTPS edit the default-ssl.conf or your own ssl configuration file in the directory /etc/apache2/sites-available
SSLEngine on
SSLCertificateFile path_to_ssl_certificate
SSLCertificateKeyFile path_to_ssl_certificate_key_file
2.b.  To setup for HTTPS edit the ports.conf in the directory /etc/apache2. Comment or remove the line,
Listen 80
2.c. Enable SSL mod using
sudo a2enmod ssl
3. Apache server restart can be done using any of the below commands,
systemctl reload apache2.service
service apache2 reload
service apache2 restart
/etc/init.d/apache2 restart
4. Enable or disable ssl enabled site configurations using commands,
a2ensite default-ssl.conf
a2dissite default-ssl.conf
5. To open directory with Admin power, use
gksu nautilus path_to_directory
6. Replace the /home/svn with path to svn root

7. Replace the /home/svn/MyProject with Repository path

8. Replace /svn in HTTP(S) url with the location provided inside the tag <Location>