How to Set Up an Apache Subversion (SVN) Server on CentOS 7

Apache Subversion (SVN) is a popular version control system that allows storage of various file versions, such as source code and documentation.

This guide demonstrates how to utilize Apache Subversion and Apache to configure an SVN server on a CentOS 7 server instance.

Prerequisites

  • A virtual machine running CentOS 7 (a minimal installation is recommended but not mandatory).
  • A sudo user for system access.

Step 1: System Update

Execute the following commands to update the system:

sudo yum update
sudo shutdown -r now

After the reboot process completes, log in again using the same sudo user credentials.

Step 2: Apache Installation

Install Apache through YUM with the command below:

Next, remove Apache’s default welcome page using:

sudo sed -i 's/^/#&/g' /etc/httpd/conf.d/welcome.conf

Disable Apache’s file listing in the /var/www/html directory with the following command:

sudo sed -i "s/Options Indexes FollowSymLinks/Options FollowSymLinks/" /etc/httpd/conf/httpd.conf

 

Step 3: Install SVN and the mod_dav_svn Module

To integrate SVN with Apache, it is necessary to install the additional Apache module named “mod_dav_svn” along with SVN itself:

sudo yum install subversion mod_dav_svn

Step 4: SVN Configuration

1) Edit the SVN Configuration File

Open the SVN configuration file with the following command:

sudo vi /etc/httpd/conf.modules.d/10-subversion.conf

The content of the file should look like this:

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

Next, append the following section:

<Location /svn>
  DAV svn
  SVNParentPath /svn
  AuthName "SVN Repos"
  AuthType Basic
  AuthUserFile /etc/svn/svn-auth
  AuthzSVNAccessFile /svn/authz
  Require valid-user
</Location>

Save the file and exit the editor:

Note: This configuration defines an HTTP authentication file at /etc/svn/svn-auth and a permission control file at /svn/authz. These files will be created in later steps.

2) Create an SVN Repository

Create a directory for SVN repositories and set up the first repository using the commands below:

sudo mkdir /svn
cd /svn
sudo svnadmin create repo1
sudo chown -R apache:apache repo1

 

3) Create SVN User Accounts

Execute the commands below to set up the HTTP authentication file at /svn/svn-auth and create an SVN user named user001:

sudo mkdir /etc/svn
sudo htpasswd -cm /etc/svn/svn-auth user001
sudo chown root:apache /etc/svn/svn-auth
sudo chmod 640 /etc/svn/svn-auth

To add additional SVN users, use these commands:

sudo htpasswd -m /etc/svn/svn-auth user002
sudo htpasswd -m /etc/svn/svn-auth user003

Warning: Do not include the -c flag again when adding new users. Using -c will recreate the authentication file and delete all previously created accounts.

4) Assign Permissions to SVN Users

Copy the existing authorization file and open it for editing:

sudo cp /svn/repo1/conf/authz /svn/authz
sudo vi /svn/authz

Assuming the following:

  • user001 is the administrator.
  • user002 is a regular user with read and write permissions for the repository repo1.
  • user003 is a trainee allowed only to read the contents of repo1.

Adjust the permission settings like this:

[groups]
admin=user001
repo1_user=user002
repo1_trainee=user003

[/]
@admin=rw

[repo1:/]
@repo1_user=rw
@repo1_trainee=r

Save and exit the editor:

 

Step 5: Launch Apache and Adjust Firewall Settings

Initiate the Apache service using the following commands:

sudo systemctl start httpd.service
sudo systemctl enable httpd.service

Allow traffic for the HTTP service through the firewall with these commands:

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload

Finally, you can connect to the SVN repository repo1 from an SVN client by navigating to the following URL:

http://<your-server-ip>/svn/repo1/

 

 

Conclusion

By following the steps outlined in this guide, you have successfully set up an SVN server using Apache Subversion and Apache on a CentOS 7 instance. You learned how to install necessary packages, configure the SVN service, create user accounts with appropriate permissions, and enable HTTP access through the firewall. Your SVN repository is now ready for version control operations, and users can easily connect to it through their SVN clients. This setup provides a reliable and efficient environment for managing project files and collaborating with team members.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: