Install & Configure Apache Subversion (SVN) on CentOS 7

Apache Subversion is also known as SVN, is an open source versioning & revision controlling program which helps in storing the present and past historic file versions like documents, source codes and web pages. SVN comes under Apache License.

In this article we will install & configure SVN on CentOS 7, which will act as SVN repository where authenticated users will be allowed to perform check-in and checkout operations.

Step:1 Install SVN & Apache Packages

SVN & Apache (http) package are available in the default CentOS 7 repository. Use below yum command to install required packages :

[root@localhost ~]# yum install httpd subversion mod_dav_svn

Step:2 Edit the configuration file of Apache Subversion

Add the below lines in the config file (/etc/httpd/conf.modules.d/10-subversion)

[root@localhost ~]# vi /etc/httpd/conf.modules.d/10-subversion.conf
Alias /svn /var/www/svn
<Location /svn>
DAV svn
SVNParentPath /var/www/svn/
AuthType Basic
AuthName "SVN Repository"
AuthUserFile /etc/svn-auth-accounts
Require valid-user
</Location>

Above settings will allow only the authenticated users to use SVN repository.

Step:3 Create SVN Users using htpasswd command.

[root@localhost ~]# htpasswd -cm /etc/svn-auth-accounts linuxtechi
New password:
Re-type new password:
Adding password for user linuxtechi

In the above htpasswd command we have used ‘-c‘ & ‘-m‘ options. -c is used to create the password file ( /etc/svn-auth-accounts) and -m used to create MD5 encryption password for the user. To create second user remove the ‘-c’ from the above command otherwise it will overwrite existing file.

[root@localhost ~]# htpasswd -m /etc/svn-auth-accounts jack
New password:
Re-type new password:
Adding password for user jack

Step:4 Create & Configure SVN Repository

[root@localhost ~]# mkdir /var/www/svn
[root@localhost ~]# cd /var/www/svn/
[root@localhost svn]# svnadmin create repo
[root@localhost svn]# chown apache.apache repo/
Note : In case Selinux is enable then apply below selinux rules.
[root@localhost svn]# chcon -R -t httpd_sys_content_t /var/www/svn/repo/
[root@localhost svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/repo/

Step:5 Start & enable the apache (httpd) service

[root@localhost ~]# systemctl restart httpd.service
[root@localhost ~]# systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@localhost ~]#

Step:6 Try to access SVN repo from web browser.

svn-web

In the browser just replace ip address with your SVN Server’s IP

repo-revision

Step:7 Disable anonymous access on SVN Repository

Edit the file – /var/www/svn/repo/conf/svnserve.conf, add the below two lines

## Disable Anonymous Access
anon-access = none

## Enable Access control
authz-db = authz

Step:8 Import Project Directory’s Content to SVN repository

Let’s first create Sample Project Directory and its file.

[root@localhost ~]# cd /mnt/
[root@localhost mnt]# mkdir linuxproject
[root@localhost mnt]# cd linuxproject/
[root@localhost linuxproject]# touch testfile_1 ; touch testfile_2

Now use SVN command to import linuxproject to the repo. As we have created sample linuxproject on the svn server itself.

[root@localhost linuxproject]# svn import -m "First SVN Repo" /mnt/linuxproject/ file:///var/www/svn/repo/linuxproject
Adding testfile_1
Adding testfile_2
Committed revision 1.
Now Check from the Browser

linuxproject_svn

Step:9 Check Out the Project

In my case i want to checkout the linuxproject on my ubuntu laptop using SVN command. So to perform checkout operations please make your system has subversion package installed, if not then use “apt-get install subversion” command to install required package.

linuxtechi@localhost:~$ mkdir svn_data
linuxtechi@localhost:~$ pwd
/home/linuxtechi
linuxtechi@localhost:~$ svn co http://192.168.1.16/svn/repo/linuxproject /home/linuxtechi/svn_data/ --username jack
Authentication realm: <http://192.168.1.16:80> SVN Repository
Password for 'jack': ********
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
<http://192.168.1.16:80> SVN Repository
can only be stored to disk unencrypted! You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible. See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/home/linuxtechi/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
A svn_data/testfile_1
A svn_data/testfile_2
Checked out revision 1.

Step:10 Committing Changes

After making required changes in the project code , we can commit the changes to the SVN repos. In My case i have created one more file in linuxproject folder.

linuxtechi@localhost:~$ cd /home/linuxtechi/svn_data/
linuxtechi@localhost:~/svn_data$ touch testfile_3
linuxtechi@localhost:~/svn_data$ svn add testfile_3 --username jack
A testfile_3
linuxtechi@localhost:~/svn_data$ svn commit -m "New File addedd" --username jack
Adding testfile_3
Transmitting file data .
Committed revision 2.
Note: While committing the changes if you are getting below error

svn: E000013: Commit failed (details follow):

svn: E000013: could not begin a transaction

Then to solve this error , make sure that apache user has read & write access to the entire repository.

[root@localhost repo]# chown -R apache:apache *
[root@localhost repo]# chmod -R 664 *

11 Responses

  1. jdros says:

    Nice article with well-explained procedure. BUT.
    The real tricky part for the source-control tools is the authentication. Especially if/when you want to open-up your server to the public.

    Obviously you (really) need to avoid storing your password unencrypted!

    The latest trend is to use SSH-keys instead of username/password. Is it possible with SVN?

  2. Josef Chmel says:

    Hi.
    Directive Alias /svn /var/www/svn causes “svn: E195019: Redirect cycle detected for URL ‘http://….” error and you are unable to do checkout for example! Problem detected on Centos 7 , Server version: Apache/2.4.6 (CentOS), svn version 1.7.14

    # vi /etc/httpd/conf.modules.d/10-subversion.conf
    Alias /svn /var/www/svn

    Commenting out # Alias /svn /home/testsvn solves this problem – after a few hours of googling and pounding my head against the wall.

  3. David says:

    Thank you Josef !! You save me for a lot of time !!

  4. Bernat says:

    Hello, I am following the tutorial and I think I’ve got it all right. But now I do not interpret php files, if I agree to index.php is downloaded to my computer, it seems that does not recognize the php, but if I access the HTML if it looks good.
    Do you know if I have to set something else to see the php?
    Thank you !!

  5. iis says:

    hello…
    very nice tutorial but only one thing is in step 8 when i try to import i am getting a error E205000:Invalid URL…. please help me

    • Pradeep Kumar says:

      Can you give me the full command which you are trying to run to import sample project. In my Case i am using file

  6. Harvey says:

    The result of: svn import -m “First SVN Repo” /mnt/linuxproject
    or
    svn import -m “First SVN Repo” –username MYUSER–password MYPASSWORD /mnt/linuxproject
    results in this console output:
    svn: E205000: Try ‘svn help’ for more info
    svn: E205000: Invalid URL ‘/mnt/linuxproject’

    • Harvey says:

      sorry for copy and paste error… the -username and -password really are two hyphens, not a long dash.

    • Harvey says:

      Never mind. I figured out the problem. It works when we append the URL of the server, for example:
      #svn import -m “First SVN Repo” –username MYUSER –password MYPASSWORD /mnt/linuxproject ‘http://MYSERVER/svn/repo’
      (above should show hyphen hyphen before username and password switches; if it shows long dash, it really should be hyphen hyphen)

    • Harvey says:

      svn import is giving me this error:
      svn: E175011: Repository moved permanently to ‘http://MYSERVER/svn/repo’; please relocate

  1. September 28, 2015

    […] Install SVN or Apache Subversion on CentOS 7 […]

Leave a Reply

Your email address will not be published. Required fields are marked *