The Ultimate Guide to Setting Up Apache Subversion SVN and TortoiseSVN For Version Control

If your work requires handling documents, web pages, and other type of files that are regularly updated, you may want to use a version control mechanism if you are not doing so already.

Among other things, this allows you (and a group of potential collaborators as well) to track changes made to a given file, and lets you roll back to a previous version if an issue is encountered or when an update has not produced the expected result.

In the free software ecosystem, the most-widely used version control system is called Apache Subversion (or SVN for short). With the help of mod_dav_svn (Apache’s module for Subversion), you can access a Subversion repository using HTTP and a web server.

That said, let’s roll up our sleeves and install these tools on a RHEL / CentOS 7, Fedora 22-24, Debian 8/7 and Ubuntu 16.04-15.04 server. For our tests we will use a CentOS 7 server with IP 192.168.0.100.

On the client side (a Windows 7 machine), we will install and use TortoiseSVN (which is based on Apache Subversion) as an interface to SVN.

Our Testing Environment

Server - CentOS 7
IP Address - 192.168.0.100
Client - Windows 7

Step 1 – Installing and Configuring SVN on Linux

As we just mentioned, we will rely on Apache in order to access the SVN repository using a web interface. If it is not installed already, make sure to add it to the list of packages as shown below:

------------------ On CentOS / RHEL / Fedora ------------------ 
# yum update && yum install mod_dav_svn subversion httpd -y

------------------ On Debian / Ubuntu ------------------ 
# apt-get update && apt-get install libapache2-svn subversion apache2 -y 

During installation on CentOS 7, an Apache configuration file for SVN will be created as /etc/httpd/conf.modules.d/10-subversion.conf. Open the file and add the following configuration block:

/etc/httpd/conf.modules.d/10-subversion.conf
<Location /svn>
    DAV svn
    SVNParentPath /websrv/svn
    AuthType Basic
    AuthName "Welcome to SVN"
    AuthUserFile /etc/httpd/subversion-auth
    Require valid-user
</Location>
Configure Apache SVN Module
Configure Apache SVN Module

Note: On Debian / Ubuntu you need to add below lines to /etc/apache2/mods-enabled/dav_svn.conf file.

/etc/apache2/mods-enabled/dav_svn.conf
<Location /svn>
    DAV svn
    SVNParentPath /websrv/svn
    AuthType Basic
    AuthName "Welcome to SVN"
    AuthUserFile /etc/apache2/subversion-auth
    Require valid-user
</Location>

On Debian / Ubuntu, you need to enable dav_svn Apache module:

# a2enmod dav_svn

A couple of clarifications:

  1. The SVNParentPath directive indicates the directory where our repositories will be later created. If this directory does not exist (which is most likely the case), create it with:
    # mkdir -p /websrv/svn
    

    It is important to note that this directory must NOT be located inside, or overlap, the DocumentRoot of a virtual host currently being served by Apache. This is a showstopper!

  2. The AuthUserFile directive indicates the file where the credentials of a valid user will be stored. If you want to allow everyone to access SVN without authentication, remove the last four lines in the Location block. If that is the case, skip Step 2 and head directly to Step 3.
  3. Although you may be tempted to restart Apache in order to apply these recent changes, don’t do it yet as we still need to create the authentication file with valid users for SVN, and the repository itself.

Step 2 – Add Allowed Users to Access SVN

We will now use htpasswd to create a password for accounts that will be allowed to access SVN. For the first user only, we will need the -c option.

Allowed accounts and bcrypt-encrypted passwords (-B) will be stored in /etc/httpd/subversion-auth in key-value pairs. Note that by today’s standards, the default MD5 or SHA encryption used by htpasswd are considered insecure.

------------------ On CentOS / RHEL / Fedora ------------------ 
# htpasswd -cB /etc/httpd/subversion-auth tecmint

------------------ On Debian / Ubuntu ------------------ 
# htpasswd -cB /etc/apache2/subversion-auth tecmint

Don’t forget to set the right ownership and permissions to the authentication file:

------------------ On CentOS / RHEL / Fedora ------------------ 
# chgrp apache /etc/httpd/subversion-auth
# chmod 660 /etc/httpd/subversion-auth

------------------ On Debian / Ubuntu ------------------ 
# chgrp www-data /etc/apache2/subversion-auth
# chmod 660 /etc/apache2/subversion-auth

Step 3 – Add Security and Create SVN Repository

Since you will be accessing SVN via a web interface, you will need to allow HTTP (and optionally HTTPS) traffic through your firewall.

------------------ On CentOS / RHEL / Fedora ------------------ 
# firewall-cmd --add-service=http --permanent
# firewall-cmd --add-service=https --permanent
# firewall-cmd --reload 

By reloading the firewall configuration with --reload, the permanent settings are put into effect immediately.

Create an initial SVN repository called tecmint:

# svnadmin create /websrv/svn/tecmint

Change the owner and group owner to apache recursively:

------------------ On CentOS / RHEL / Fedora ------------------ 
# chown -R apache:apache /websrv/svn/tecmint

------------------ On Debian / Ubuntu ------------------ 
# chown -R www-data:www-data /websrv/svn/tecmint

Finally, you will need to change the security context of /websrv/svn/tecmint (note that you will have to repeat this step if you decide to create other repositories later):

------------------ On CentOS / RHEL / Fedora ------------------ 
# chcon -R -t httpd_sys_content_t /websrv/svn/tecmint/
# chcon -R -t httpd_sys_rw_content_t /websrv/svn/tecmint/

Note: The last two commands may not apply if you’re installing SVN on a VPS with SELinux disabled.

Suggested Read: Learn How to Disable SELinux Temporarily or Permanently in Linux

Restart Apache and verify the repository is available.

------------------ On CentOS / RHEL / Fedora ------------------ 
# systemctl restart httpd

------------------ On Debian / Ubuntu ------------------ 
# systemctl restart apache2

Then launch a web browser and point it to http://192.168.0.100/svn/tecmint. After entering the credentials for the valid user that we created in Step 1, the output should be similar to:

Access SVN Repository via Browser
Access SVN Repository via Browser

At this point we have not added any code to our repository. But we will do that in a minute.

Step 4 – Install TortoiseSVN in the Windows 7 Client

As we mentioned in the introduction, TortoiseSVN is an user-friendly interface to Apache Subversion. It is Free Software licensed under the GPL and can be downloaded from https://tortoisesvn.net/downloads.html.

Choose the architecture (32 or 64-bit) that corresponds to your machine and install the program before proceeding.

Step 5 – Setup SVN Repository on Client Machine

In this step we will use a folder named webapp inside Documents. This folder contains a HTML file, and two folders named scripts and styles with a Javascript and a CSS file (script.js and styles.css, respectively) that we want to add to version control.

Right click webapp and choose SVN Checkout. This will create a local copy of the remote repository (which is empty at the moment) and initialize the folder for version control:

Configure SVN on Client Directory
Configure SVN on Client Directory

In URL of repository, type http://192.168.0.100/svn/tecmint and make sure the local checkout directory remains the same, then click OK:

Configure SVN Repository on Client
Configure SVN Repository on Client

Enter the username and password (refer to Step 2) and click OK:

Enter Credentials of SVN User
Enter Credentials of SVN User

You will be asked whether you want to checkout into a non-empty directory. Confirm to proceed with the checkout. Once it is complete, a green checkmark will appear next to the folder name:

Check Out SVN Directory
Check Out SVN Directory

Step 6 – Commit Changes and Deploy Files to Remote SVN Repository

Right click on webapp again and choose Commit this time. Next, write a descriptive comment to later identify this commit, and check the files and folders you want to deploy to the repository. Finally, click OK:

Deploy Files to Remote SVN Repository
Deploy Files to Remote SVN Repository

Depending on the size of files, the commit should not take more than a minute. When it is complete, you will see that we are now on revision 1, which matches the version and files listed in the web interface:

Confirm SVN Repository Revision
Confirm SVN Repository Revision

If there are several people working on the same files, you’ll want to Update your local copy in order to have the latest version available to work on. You can do that by right clicking on webapp and choosing Update from the context menu.

Congratulations! You have successfully setup a SVN server and commited / updated a simple project under version control.

Summary

In this article we have explained how to install and configure an Apache Subversion repository server on a CentOS 7 server, and how to commit changes to that repository using TortoiseSVN.

Please note there is much more to SVN and TortoiseSVN than what we can adequately cover here (specially how to return to previous revisions), so you may want to refer to the official docs (SVN and TortoiseSVN) for more information and configuration cases.

As always, don’t hesitate to let us know if you have any questions! Feel free to use the comment form below to reach us anytime.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Gabriel Cánepa
Gabriel Cánepa is a GNU/Linux sysadmin and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

16 Comments

Leave a Reply
  1. Hi,

    I could successfully complete the svn serer installation, but I get

    Forbidden

    You don’t have permission to access this resource.
    Apache/2.4.41 (Ubuntu) Server at 192.168.1.141 Port 8090

    Message while accessing it through URL…

    Reply
  2. Hello

    I’m getting the error `Unable to locate package libapache2-svn’ when trying to do this tutorial. I’m on a Debian 9 server.

    Does anyone know what is happening?

    Reply
  3. this is perfect thank you. i just have one question i want to install this on my raspberry pi i have tried a few other tutorials but they have not seemed to work. is there anything different i would need to do in order to get this working with my raspberry pi?

    Reply
    • Hi Jake,
      What kind of Raspberry Pi do you have and which operating system / version are you running on it?

      Reply
      • Hi, Iam running Noobs v2.7.0 Raspian (i believe its Debian OS, the latest version.

        RASPBIAN STRETCH WITH DESKTOP
        Image with desktop based on Debian Stretch
        Version:March 2018
        Release date:2018-03-13)

        Reply
    • @Naidu,
      The article is little outdated and we haven’t updated it to the latest release..give us some to update the article..make it 100% working on all Linux flavors…

      Reply
  4. Hello Sir
    I am new to Linux World. I am using Ubuntu 14.04.So how can i install this SVN (Subversion) 1.7 Server Using uberSVN 12.4 in Ubuntu 14.04. Please reply sir.

    Thank You…

    Reply
  5. Pingback: Install GIT to Create and Share Your Own Projects on GITHub Repository

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.