How to Set Up an Apache Subversion (SVN) Server on AlmaLinux 9 or Rocky Linux 9
Serve Subversion repositories over HTTP with Apache and mod_dav_svn on AlmaLinux 9 or Rocky Linux 9, with password logins and per-repository permissions.
This guide sets up an Apache Subversion (SVN) server on AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9. Repositories are served over HTTP by Apache with the mod_dav_svn module, users log in with a password, and a single access file decides who can read or write each repository.
CentOS 7 reached end of life in June 2024 and no longer receives security fixes. The RHEL 9 family replaces it and still ships everything needed here: the subversion and mod_dav_svn packages are in the standard AppStream repository (Subversion 1.14), so no third-party repository is required.
Requirements
- A server running AlmaLinux 9, Rocky Linux 9 or CentOS Stream 9.
- A user with
sudorights (the examples usedeploy). All commands are run as that user. - The server's address or a DNS name pointing to it. The examples use
203.0.113.10andsvn.example.com.
Install pending updates first:
sudo dnf update -yStep 1: Install Apache, Subversion and mod_dav_svn
One command installs the web server, the Subversion tools and the Apache module that speaks the Subversion protocol:
sudo dnf install -y httpd subversion mod_dav_svnThe mod_dav_svn package adds /etc/httpd/conf.modules.d/10-subversion.conf, which loads mod_dav_svn and mod_authz_svn. You do not need to edit that file. Check the installed version:
svnadmin --version --quietStep 2: Create a repository
Keep all repositories under one parent directory. /var/www/svn is the best choice on this family of systems because the default SELinux policy already labels that path as writable web content (httpd_sys_rw_content_t), so SELinux can stay in enforcing mode.
sudo mkdir -p /var/www/svn
sudo svnadmin create /var/www/svn/repo1
sudo chown -R apache:apache /var/www/svn
sudo restorecon -R /var/www/svnApache runs as the apache user and needs read and write access to the repository files, which is what the chown is for. restorecon applies the SELinux labels to the new files. Repeat svnadmin create, chown and restorecon for each additional repository.
Step 3: Create user accounts
Passwords are stored in an htpasswd file outside the web root. Create it with the first user; -B selects bcrypt hashing:
sudo mkdir /etc/svn
sudo htpasswd -c -B /etc/svn/svn-auth.htpasswd aliceAdd more users without -c. That option recreates the file and would erase the accounts already in it.
sudo htpasswd -B /etc/svn/svn-auth.htpasswd bob
sudo htpasswd -B /etc/svn/svn-auth.htpasswd carolTo remove a user later, run sudo htpasswd -D /etc/svn/svn-auth.htpasswd carol.
Step 4: Define who can access what
Create the access file:
sudo vi /etc/svn/authzIn this example alice administers everything, bob can read and write repo1, and carol can only read it:
[groups]
admins = alice
repo1-developers = bob
repo1-readers = carol
[/]
@admins = rw
[repo1:/]
@repo1-developers = rw
@repo1-readers = rA section name is [repository:/path]; [/] applies to the root of every repository. Permissions are inherited by subdirectories, r is read-only, rw is read and write, and an empty value (carol =) denies access to that path. Anyone not matched by a rule gets no access.
Make both files readable by Apache but not by other local users:
sudo chown root:apache /etc/svn/svn-auth.htpasswd /etc/svn/authz
sudo chmod 640 /etc/svn/svn-auth.htpasswd /etc/svn/authzStep 5: Configure Apache
Create a configuration file for the Subversion location:
sudo vi /etc/httpd/conf.d/subversion.confAdd:
<Location /svn>
DAV svn
SVNParentPath /var/www/svn
AuthType Basic
AuthName "Subversion repositories"
AuthUserFile /etc/svn/svn-auth.htpasswd
AuthzSVNAccessFile /etc/svn/authz
Require valid-user
</Location>SVNParentPath tells Apache that every directory under /var/www/svn is a repository, so repo1 becomes available at /svn/repo1 and new repositories appear without further Apache changes. Require valid-user forces a login for every request, and AuthzSVNAccessFile applies the rules from Step 4.
Check the syntax, then start Apache and enable it at boot:
sudo apachectl configtest
sudo systemctl enable --now httpdStep 6: Open the firewall
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reloadStep 7: Test from a client
On a workstation with a Subversion client installed, check out the empty repository as a user with write access:
svn checkout http://203.0.113.10/svn/repo1 --username bobCreate the conventional layout and commit it:
cd repo1
svn mkdir trunk branches tags
svn commit -m "Create standard layout"Now try the same commit as carol. It must be refused, which proves that the access file is being applied. You can also open http://203.0.113.10/svn/repo1 in a browser to see a read-only listing after logging in.
Protect the passwords with HTTPS
Basic authentication sends the user name and password with every request, only base64-encoded. Over plain HTTP anyone on the network path can read them, so use HTTP only for testing. For real use, install mod_ssl, configure a certificate for svn.example.com in an HTTPS virtual host, and have clients use https://svn.example.com/svn/repo1. The <Location /svn> block stays the same.
sudo dnf install -y mod_ssl
sudo systemctl restart httpdBackups and troubleshooting
Back up a repository while the server is running with svnadmin hotcopy, or write a portable dump file:
sudo svnadmin hotcopy /var/www/svn/repo1 /var/backups/repo1-hotcopy
sudo sh -c 'svnadmin dump /var/www/svn/repo1 > /var/backups/repo1.dump'Restore a dump into a newly created repository with svnadmin load /var/www/svn/newrepo < repo1.dump, then repeat the chown and restorecon commands from Step 2.
- 403 Forbidden for a valid user: the user has no matching rule in
/etc/svn/authz, or the repository name in the section header is misspelled. - Commits fail with a permission error: files in the repository are not owned by
apache(often after runningsvnadminas root) or have the wrong SELinux label. Run thechownandrestoreconcommands again and look at/var/log/httpd/error_log. - Repositories outside
/var/www/svn: they do not get the right SELinux label automatically. Either keep them under/var/www/svnor add your own file-context rule withsemanage fcontext.
Frequently asked questions
Which Subversion version does the RHEL 9 family provide?
AppStream carries the 1.14 series. Upstream now develops 1.15 and keeps 1.14 on security and critical fixes; the distribution maintains its own package for the life of the release. Clients on other versions can talk to a 1.14 server.
Can I allow anonymous read access?
Yes. Add * = r to the relevant section of the access file and replace Require valid-user with a configuration that only asks for a login when it is needed; the Subversion book describes this under mixed anonymous and authenticated access. Only do this for repositories that are meant to be public.
Do I need to restart Apache after changing users or permissions?
No. The password file and the access file are read when requests are handled, so new users and changed rules take effect immediately. Only changes to files under /etc/httpd need sudo systemctl reload httpd.
Should I use svnserve instead of Apache?
svnserve is lighter and uses the svn:// protocol on port 3690, but it has no TLS of its own. Apache with mod_dav_svn works through ordinary web ports and proxies and is the usual choice when users connect over the internet.