Home arrow Guides arrow Build a Subversion Server with FreeBSD
Build a Subversion Server with FreeBSD PDF
Thursday, 25 February 2010

This tutorial show step by step configuration of a Subversion Server on FreeBSD. It is not a SVN for FreeBSD source files but a version server for your projects. What's the use? Well, if your project is large and you want to manage versions of your source files, bugs and features and you want a track of how your workers did their jobs every day, Subversion might be the answer.

Step 1. Install FreeBSD
Get the last IMAGE of FreeBSD from ftp.freebsd.org. You can use USB version which is easely to install. Install it, then cvsup to the stable version.

You can do that using this tutorial: http://www.freebsdonline.com/content/view/460/476/

Step 2. Build Subversion from ports
Execute the following commands:

cd /usr/ports/devel/subversion
make install clean

Step 3. Install PHP and Apache (for use with websvn)
cd /usr/ports/www/apache22
make install clean

Add the following lines to /usr/local/etc/apache22/httpd.conf (to load index.php and support PHP)
(If you already have dir_module section, just add ther index.php)

<IfModule dir_module>
    DirectoryIndex index.html index.php

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

Then, compile php.

cd /usr/ports/lang/php5
make install clean

Don't forget check APACHE MODULE before compiling, then compile and install, so your Apache would be able to run PHP scripts.

You must configure Apache to run PHP.

Step 4. Install and configure WebSVN
cd /usr/ports/devel/websvn
make install clean

Then copy /usr/local/www/websvn/include/distconfig.php to /usr/local/www/websvn/include/config.php

Add the following lines:

$config->addRepository('The SVN SERVER', 'file:///home/svn/repositories/svntest/');

Then create /usr/local/etc/apache22/Includes/aliases.conf file with the following content:

Alias /websvn "/usr/local/www/websvn"
<Directory "/usr/local/www/websvn">
  Options Indexes FollowSymLinks
  RewriteEngine on
  AllowOverride All
  Order allow,deny
  Allow from all

If you want to password protect your websvn directory also add:

  AuthType Basic
  AuthUserFile /usr/local/www/websvn/.htpasswd
  AuthName "Restricted Files"
  Require valid-user

to previous <Directory ...> ... </Directory> section.

And then create a .htpasswd file with command:

  htpasswd -c /usr/local/www/websvn/.htpasswd admin

Then you will be abble to login using user admin and password you've just added.

Then don't forget to restart Apache.

Step 5. Configure Subversion
We will first create a subversion repository where our revisions will be placed :

install -v -m 0755 -d /home/svn
install -v -m 0755 -d /home/svn/repositories
svnadmin create --fs-type fsfs /home/svn/repositories/svntest/
cd /home/svn/repositories/svntest/
mkdir branches tags trunk

Step 7. Start the svnserve server

svnserve -d -r /home/svn/repositories/svntest

Step 8. Test commiting to the SVN server from local

If you try to commit you might get an error regarding writting rights. In that case create a group for all your users and give chown to that group to your svn repository.

To test a svn server from localhost (from the same machine) do a checkout of your svn server, then modify a file and do a commit.
.... put here example commands ....

To access a svn repository from localhost use file:/// in front of your svn path.
... put here example ....

Step 9. Configure svnserve
Create /usr/local/etc/svnserve.conf file with the following content:

password-db = userfile
realm = example realm
anon-access = read
auth-access = write

user = 12345

Here user is the username and 12345 is the password. With this settings authenticated users will have read/write privileges and anonymous users only read access.

Next, add the following lines in /etc/rc.conf:


svnserve_flags="-d --listen-port=3690 --listen-host"
Where is your SVN server IP, and /home/svn/repositories is the directory for your SVN repository.

Then start the service with:
/usr/local/etc/rc.d/svnserve start

Step 10. Using SVN remotely using SSH from other machine
You can connect to a SVN server from your command line (in Linux / BSD / OSX / Unix) or you can use TortoiseSVN and use from Windows.
For using TortoiseSVN to connect to the SVN server see step 12.

From command line you must first do a initial checkout with:

svn checkout svn+ssh:// This e-mail address is being protected from spam bots, you need JavaScript enabled to view it /home/svn/repository/project

After issuing a svn checkout command note that the local copy of SVN is in a folder, you must after checkout to change directory to that folder.

And then commit to ssh with:

svn commit

 If you want to use SSH on a nonstandard port you must configure subversion client locally to use other SSH port.
To do that edit:
edit ~/.subversion/config              // on your local client machine

and on section [tunnels] add (for example, asuming your ssh server is running on 2224):
ssh2224 = /usr/bin/ssh -p 2224

Then do a checkout with ssh2224:

svn checout svn+ssh2224:// This e-mail address is being protected from spam bots, you need JavaScript enabled to view it /home/svn/repository/project

Step 11. Configure SSHd with keys
To be able to login on SVN server without password you must configure SSH server to accept authentication without username/password, based on keys.

A tutorial about configuring SSHd server to accept authentication on pair of private/public keys and not on username/password can be found here:

http://www.freebsdonline.com/content/view/458/474/   -  SSH Public key based authentication

Step 12. Using SVN from a Windows station with TortoiseSVN
... to add ...

Remove path to putty from TortoiseSVN config, otherwise you will not be able to connect.
It will still use putty. When you will connect to SVN server from TortoiseSVN use instead of hostname of SVN server a setting name you've saved in your putty for that server IP/Hostname to connect to.

To connect to a SVN server from TortoiseSVN first do a checkout:

svn+ssh:// This e-mail address is being protected from spam bots, you need JavaScript enabled to view it /home/svn/repository/project

is your SVN server
- user
is your username on that server
- /home/svn/repository/project
- is your path to the project in the SVN server

Step 13. Using SVN from OSX
To use SVN from OSX install SCPlugin, which is similar to TortoiseSVN, well, it's much simpler with base functionality but we hope in time will mature to be similar to TortoiseSVN.

installing SCPlugin following documentation available in the downloadable .dmg you must configure your SSHd service from your SVN server to accept connection from your OSX station based on public keys and not on username/password.

SCPlugin will not work without configuring SSHd service from your SVN server to accept public keys authentication.

Other tips
Best advice is to create all your svn users to be members of group svn and then:

chown -R svn:svn /home/svn/
chmod -R 775 /home/svn/repositiories

To add a user to svn group in FreeBSD use:

pw usermod george -G svn

(will add user george to svn group)

pw groupmod svn -M svn, john, george, johny
(will modify group svn and add users svn, john, george, johny to it. All other users from group svn will be removed).

To verify if you've really added a user to a group use id command:
id george

uid=1001(george) gid=0(wheel) groups=0(wheel),1002(svn)

Useful Subversion Commands
List files/dirs from repository:   svn list file:///home/srv/svn/repositories/svntest/
Sync your working copy with files from repository:  svn update
Commit your file to repository:   svn commit -m "comment 1 for file"
Add a file or directory to your local project:  svn add main.cc
Get files from SVN server:  svn checkout file:///home/svn/repositories/svntest/
Update your working copy with version number 2:  svn update -r 2
Show last change commited to main.cc file:  svn diff --revision PREV:COMMITTED main.cc
Import a project to a SVN server:  svn import file:///home/svn/repositories/svntest/branch -m "initial import"
Copy a branch to a new one:  svn copy file:///home/svn/repositories/svntest/trunk  file:///home/svn/repositories/svntest/project-v.0.1.1 -m "copy to a new branch for version 0.1.1"

Ignore a directory or a file:  svn propedit svn:ignore ./path 
Revert to a version (will revert to version 107):  svn update -r 107 

Other Tips
Remove .svn directories from unix shell:   find ./ -name "*.svn*" -exec rm -rf {} \;

Last Updated ( Tuesday, 07 June 2011 )
< Prev   Next >

Other BSD Systems





Best BSD firewall?