How to install Subversion on Ubuntu 18.04
This simple how to will walk through installing Subversion on Ubuntu 18.04. First step is to ensure we are up-to-date and install Apache 2:
sudo apt-get update sudo apt-get upgrade sudo apt-get install apache2
With Apache2 installed, let's install and enable the basic modules we will need to get Subversion running. Note that some tutorials suggest we also need `libapache2-lib-svn`. `libapache2-lib-svn` is most likely not present on Ubuntu 18.04, and is not required as libapache2-mod-svn does what we need:
sudo apt-get install subversion libapache2-mod-svn sudo a2enmod dav sudo a2enmod dav_svn sudo a2enmod authz_svn sudo service apache2 restart
We can now create our first repository and user to access the repository from the browser. Some tutorials suggest we should install our repositories under /var/lib, which makes the most sense. For our purposes, we will be installing under /var/www to ensure all of our site content is together in one place:
sudo mkdir /var/www/svn/ sudo svnadmin create /var/www/svn/oocrepo sudo chown -R www-data:www-data /var/www/svn sudo chmod -R 775 /var/www/svn
Let's move on to creating a user. You may create as many users as you wish, or have an automated way to manage your users. These users will give browser access to peruse the repository, and will let users access the CLI svn to clone, commit etc to our repository. Passwords will be given a more secure than average bcrypt password. Check out `man htpasswd` for more info:
sudo mkdir /var/www/svn_users sudo touch /var/www/svn_users/dav_svn.passwd sudo htpasswd -B -C 10 /var/www/svn_users/dav_svn.passwd admin
The next step is to setup apache to give us secure access to our repository:
sudo vi /etc/apache2/sites-available/outofcontrol.conf
Add this to the empty file:
<virtualhost *:80> ServerName outofcontrol.ca ServerAdmin webmaster@outofcontrol.ca DocumentRoot /var/www/html <location "/svn"> DAV svn SVNParentPath /var/www/svn # our access control policy # only authenticated users may access the repository Satisfy Any Require valid-user AuthzSVNAccessFile /var/www/svn-access # how to authenticate a user - change path to suit your needs AuthType Basic AuthName "Subversion Repository" AuthUserFile /var/www/svn_users/svn-auth # Location of option xsl file. Uncomment and change to suit your needs. SVNIndexXSLT "/css/svn/svnindex.xsl" ModMimeUsePathInfo on </location> <directory "/var/www/html"> AllowOverride None </directory> ErrorLog ${APACHE_LOG_DIR}/svn.outofcontrol.error.log CustomLog ${APACHE_LOG_DIR}/svn.outofcontrol.access.log combined </virtualhost> </Location>
Now we can disable the old Apache2 site configs and enable our new one, verify our config is good, and restart Apache:
sudo a2dissite 000-default sudo a2ensite outofcontrol // Use the name of the .conf file you create in the previous step. apachectl -t systemctl restart apache2
Now go to your browser and take pride in your new Subversion repository at https://example.com/svn/myrepo.
Making it look good!
If you wish to use CSS to style your Subversion repositories in the browser, you will need to add an XSL and CSS file:
cd /var/www/html mkdir -p css/svn vim svnindex.xsl
Paste the following into the /var/www/html/css/svn/svnindex.xsl:
<?xml version="1.0"?> <!-- A sample XML transformation style sheet for displaying the Subversion directory listing that is generated by mod_dav_svn when the "SVNIndexXSLT" directive is used. --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"></xsl:stylesheet> <xsl:output method="html"/> <xsl:template match="*"/> <xsl:template match="svn"> <html> <head> <title> <xsl:if test="string-length(index/@name) != 0"> <xsl:value-of select="index/@name"/> <xsl:text>: </xsl:text> </xsl:if> <xsl:value-of select="index/@path"/> </title> <link rel="stylesheet" type="text/css" href="/svnindex.css"/> </head> <body> <div class="svn"> <xsl:apply-templates/> </div> <div class="footer"> <xsl:text>Powered by </xsl:text> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@href"/> </xsl:attribute> <xsl:text>Subversion</xsl:text> </xsl:element> <xsl:text> </xsl:text> <xsl:value-of select="@version"/> </div> </body> </html> </xsl:template> <xsl:template match="index"> <div class="rev"> <xsl:if test="string-length(@name) != 0"> <xsl:value-of select="@name"/> <xsl:if test="string-length(@rev) != 0"> <xsl:text> — </xsl:text> </xsl:if> </xsl:if> <xsl:if test="string-length(@rev) != 0"> <xsl:text>Revision </xsl:text> <xsl:value-of select="@rev"/> </xsl:if> </div> <div class="path"> <xsl:value-of select="@path"/> </div> <xsl:apply-templates select="updir"/> <xsl:apply-templates select="dir"/> <xsl:apply-templates select="file"/> </xsl:template> <xsl:template match="updir"> <div class="updir"> <xsl:text>[</xsl:text> <xsl:element name="a"> <xsl:attribute name="href">..</xsl:attribute> <xsl:text>Parent Directory</xsl:text> </xsl:element> <xsl:text>]</xsl:text> </div> <!-- xsl:apply-templates/ --> </xsl:template> <xsl:template match="dir"> <div class="dir"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@href"/> </xsl:attribute> <xsl:value-of select="@name"/> <xsl:text>/</xsl:text> </xsl:element> </div> <!-- <xsl:apply-templates/ --> </xsl:template> <xsl:template match="file"> <div class="file"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="@href"/> </xsl:attribute> <xsl:value-of select="@name"/> </xsl:element> </div> <!-- xsl:apply-templates/ --> </xsl:template> </xsl:stylesheet>
Finally, you will need to create a CSS file to place in your site root (you can change the path if you wish for any of these files in the apache conf and the svnindex.xsl file
vim svnindex.xsl
Paste the following into the /var/www/html/css/svn/svnindex.xsl:
/* A sample style sheet for displaying the Subversion directory listing that is generated by mod_dav_svn and "svnindex.xsl". */ body{ margin: 0; padding: 0; } a { color: navy; } .footer { margin-top: 8em; padding: 0.5em 1em 0.5em; border: 1px solid; border-width: 1px 0; clear: both; border-color: #1e1e32 navy #4b5055 navy; background: #585a5c; font-size: 80%; } .svn { margin: 3em; } .rev { margin-right: 3px; padding-left: 3px; text-align: left; font-size: 120%; } .dir a { text-decoration: none; color: black; } .file a { text-decoration: none; color: black; } .path { margin: 3px; padding: 3px; background: #FFCC66; font-size: 120%; } .updir { margin: 3px; padding: 3px; margin-left: 3em; background: #FFEEAA; } .file { margin: 3px; padding: 3px; margin-left: 3em; background: #5f5f5f; } .file:hover { margin: 3px; padding: 3px; margin-left: 3em; background: #64645a; /* border: 1px black solid; */ } .dir { margin: 3px; padding: 3px; margin-left: 3em; background: #5a5a5a; } .dir:hover { margin: 3px; padding: 3px; margin-left: 3em; background: #646450; /* border: 1px black solid; */ }
The Final Product
If you now browse to http://outofcontrol.ca/svn/ooc... you should see your content (Be sure to replace the URL with your URL). It won't be pretty as you haven't added a style sheet yet. You can find a reasonable starting point for styles from this repository on Source Forge.
Make sure you enable HTTPS before getting too far. HTTP is not secure.
Let me know if this works or not, I'm happy to update the tutorial if there are bugs.