Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

SVN environment construction


May 25, 2021 SVN


Table of contents


SVN environment construction

Subversion is a popular open source version control tool. H e is free and open source on the Internet. M ost GNU/Linux distribution systems come with their own, so it's likely to already be installed on your system. Y ou can use the following commands to check if it is installed.

[jerry@CentOS ~]$ svn --version

If the Subversion client is not installed, the command reports an error, otherwise it will appear with the installed software version

[jerry@CentOS ~]$ svn --version  
-bash: svn: command not found

If you use RPM-based GNU/Linux, you can use the yum command to install and, after the svn --version command.

[jerry@CentOS ~]$ su -
Password: 
[root@CentOS ~]# yum install subversion

[jerry@CentOS ~]$ svn --version
svn, version 1.6.11 (r934486)
compiled Jun 23 2012, 00:44:03

If you are using Debian-based GNU/Linux, install it using the apt command.

[jerry@Ubuntu]$ sudo apt-get update
[sudo] password for jerry:

[jerry@Ubuntu]$ sudo apt-get install subversion

[jerry@Ubuntu]$ svn --version
svn, version 1.7.5 (r1336830)
compiled Jun 21 2013, 22:11:49

Apache installation

We've seen how to install SVN clients on GNU/Linux, so let's see how to create a new repository for users to access.

We must install the Apache httpd module and the svnadmin tool on the server. S ubversion /etc/httpd/conf.d/subversion.conf

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

<Location /svn>
   DAV svn
   SVNParentPath /var/www/svn
   AuthType Basic
   AuthName "Authorization Realm"
   AuthUserFile /etc/svn-users
   Require valid-user
</Location>

Let's create Subversion users and grant them access to the htpasswd is used to create and update plain text files that hold user names and passwords to provide basic authentication to HTTP users. -c option creates a password file that will be overwritten if it already exists. -c is only used for the first time. -m option is used to set whether MD5 encryption passwords are enabled.

The user installs

Let's create tom

[root@CentOS ~]# htpasswd -cm /etc/svn-users tom
New password: 
Re-type new password: 
Adding password for user tom

Let's create jerry

[root@CentOS ~]# htpasswd -m /etc/svn-users jerry
New password: 
Re-type new password: 
Adding password for user jerry
[root@CentOS ~]# 

Create a Subversion parent directory to hold all the work /etc/httpd/conf.d/subversion.conf

[root@CentOS ~]# mkdir /var/www/svn
[root@CentOS ~]# cd /var/www/svn/

The repository is installed

Create a repository project_repo library. svnadmin command is used to create a new repository and some other directories to hold data.

[root@CentOS svn]# svnadmin create project_repo

[root@CentOS svn]# ls -l project_repo
total 24
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 conf
drwxr-sr-x. 6 root root 4096 Aug  4 22:30 db
-r--r--r--. 1 root root    2 Aug  4 22:30 format
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 hooks
drwxr-xr-x. 2 root root 4096 Aug  4 22:30 locks
-rw-r--r--. 1 root root  229 Aug  4 22:30 README.txt

Let's change the user and group ownership of the repository.

[root@CentOS svn]# chown -R apache.apache project_repo/

Check to see if SELinux is enabled or if the SELinux state tool is not used

[root@CentOS svn]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

If SELinux is enabled, we must change the context of security.

[root@CentOS svn]# chcon -R -t httpd_sys_content_t /var/www/svn/project_repo/

If submission is allowed over HTTP, execute the following command.

[root@CentOS svn]# chcon -R -t httpd_sys_rw_content_t /var/www/svn/project_repo/

After changing these configurations, we restart the Apache server.

[root@CentOS svn]# service httpd restart
Stopping httpd:                                            [FAILED]
Starting httpd: httpd: apr_sockaddr_info_get() failed for CentOS
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
                                                           [  OK  ]
[root@CentOS svn]# service httpd status
httpd (pid  1372) is running...
[root@CentOS svn]#

Now that we've successfully configured the Apache server, we'll configure the repository, use the default authorization file to access trusted users, and add the following lines to roject_repo/conf/svnserve.conf file.

anon-access = none
authz-db = authz

As is customary, each SVN project has a trunk, label, and branch in the root directory of the project.

Trunks are directories that are primarily developed and frequently viewed by developers.

Branch directories are used to pursue different development directions.

Let's create a trunk, label, branch structure under the project repository.

[root@CentOS svn]# mkdir /tmp/svn-template
[root@CentOS svn]# mkdir /tmp/svn-template/trunk
[root@CentOS svn]# mkdir /tmp/svn-template/branches
[root@CentOS svn]# mkdir /tmp/svn-template/tags

Now import these /tmp/svn-template

[root@CentOS svn]# svn import -m 'Create trunk, branches, tags directory structure' /tmp/svn-template/ 
Adding         /tmp/svn-template/trunk
Adding         /tmp/svn-template/branches
Adding         /tmp/svn-template/tags
Committed revision 1.
[root@CentOS svn]#

It's done! We've successfully created the repository and allowed Tom and Jerry access, and from now on they can do everything the repository supports.