How to Install & Configure Apache Subversion (SVN) in CentOS 7

To Install & Configure Apache Subversion (SVN) in CentOS 7

Apache Subversion is an open source revision controlling program. It stores the historic source codes, documents, and web pages.Installation & configuration of SVN on CentOS 7 is explained in this article.


To install SVN & Apache Packages

Run the following command to install the svn & apache (http) packages.

[root@linuxhelp1 ~]# yum install httpd subversion mod_dav_svn
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.webwerks.com
 * extras: centos.webwerks.com
 * updates: centos.webwerks.com
Resolving Dependencies
-->  Running transaction check
.
.
.
Installed:
  httpd.x86_64 0:2.4.6-40.el7.centos.1            mod_dav_svn.x86_64 0:1.7.14-10.el7           
  subversion.x86_64 0:1.7.14-10.el7              

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                             apr-util.x86_64 0:1.5.2-6.el7          
  httpd-tools.x86_64 0:2.4.6-40.el7.centos.1           mailcap.noarch 0:2.1.41-2.el7          
  subversion-libs.x86_64 0:1.7.14-10.el7              

Complete!

To configure Apache Subversion

Open the configuration file in your favourite editor

[root@linuxhelp1 ~]# vim /etc/httpd/conf.modules.d/10-subversion.conf

Add the following lines.

Alias /svn /var/www/svn

DAV svn
SVNParentPath /var/www/svn/
AuthType Basic
AuthName " SVN Repository" 
AuthUserFile /etc/svn-auth-accounts
Require valid-user

Save and Quit the file.

To create SVN Users

Use htpasswd command in order to create SVN users.

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

The &ndash c option &rarr to create the password file
The &ndash m option &rarr to create MD5 encryption password for the user.

Utilise the following command to create & configure SVN Repository.

[root@linuxhelp1 ~]# mkdir /var/www/svn
[root@linuxhelp1 ~]# cd /var/www/svn
[root@linuxhelp1 svn]# svnadmin create repo
[root@linuxhelp1 svn]# chown apache.apache repo/
[root@linuxhelp1 svn]# chcon -R -t httpd_sys_content_t /var/www/svn/repo/
[root@linuxhelp1 svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/repo/

Add the http and https services in the firewall

[root@linuxhelp1 svn]# firewall-cmd --permanent --zone=public --add-service=http
success
[root@linuxhelp1 svn]# firewall-cmd --permanent --zone=public --add-service=https
success
[root@linuxhelp1 svn]# firewall-cmd --reload
success

Enable and start the http services

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

Open the web browser and try to access SVN repo using https://< IP_address> /svn/repo

To disable anonymous access on SVN Repository

Open the svnserve.conf file.

[root@linuxhelp1 svn]# vim /var/www/svn/repo/conf/svnserve.conf

Add the following lines.

anon-access = none
authz-db = authz

To import project directory’ s content to SVN repository.

[root@linuxhelp1 svn]# cd /mnt/
[root@linuxhelp1 mnt]# mkdir linuxhelpproject
[root@linuxhelp1 mnt]# cd linuxhelpproject/
[root@linuxhelp1 linuxhelpproject]# touch testfile_1   touch testfile_2
[root@linuxhelp1 linuxhelpproject]#

Run the SVN command to import the linuxhelpproject to the repo.

[root@linuxhelp1 linuxhelpproject]# svn import -m " First SVN Repo"  /mnt/linuxhelpproject/ file:///var/www/svn/repo/linuxhelpproject
Adding         testfile_1
Adding         testfile_2

Committed revision 1.

Open the browser and navigate to https://< IP_address> /svn/repo

Comment
shankar
Apr 26 2018
I had committed from client machine to svn repo , i had created repo in /var/www/svn/ after committing the project structure is not visible . But when i had checked in browser the status was updated. Please help me to solve
Add a comment
FAQ
Q
How do I check out the Subversion code?
A
Use the Subversion client:
# svn co http://svn.apache.org/repos/asf/subversion/trunk subversion
Q
Under htpasswd for svn what type of authentication is used?
A
This is basic authentication which undergoes base64 encoding
Q
I wanna enable only for certain users?
A
disable anonymous access on SVN Repository,
" /var/www/svn/repo/conf/svnserve.conf"
anon-access = none
authz-db = authz
Q
How to import already created project to it?
A
Gfirst mount your project under a mount point and then follow svn import -m "First SVN Repo" /mnt/linuxhelpproject/ file:///var/www/svn/repo/linuxhelpproject
Q
Installation procedure for Fedora, please?
A
Run the following command,
# dnf install httpd subversion mod_dav_svn