Subscribe to How-To Geek

Install Subversion with Web Access on Ubuntu

This article covers installing subversion with the apache module so that it can be easily accessed from other systems on a public network. If you want a more secure svn server, you could use svnserve+ssh, which isn't covered in this article.

To install subversion, open a terminal and run the following command:

sudo apt-get install subversion libapache2-svn

We're going to create the subversion repository in /svn, although you should choose a location that has a good amount of space.

sudo svnadmin create /svn

Next we'll need to edit the configuration file for the subversion webdav module. You can use a different editor if you'd like.

sudo gedit /etc/apache2/mods-enabled/dav_svn.conf

The Location element in the configuration file dictates the root directory where subversion will be acessible from, for instance: http://www.server.com/svn

<Location /svn>

The DAV line needs to be uncommented to enable the dav module

# Uncomment this to enable the repository,
DAV svn

The SVNPath line should be set to the same place your created the repository with the svnadmin command.

# Set this to the path to your repository
SVNPath /svn

The next section will let you turn on authentication. This is just basic authentication, so don't consider it extremely secure. The password file will be located where the AuthUserFile setting sets it to…  probably best to leave it at the default.

# Uncomment the following 3 lines to enable Basic Authentication
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /etc/apache2/dav_svn.passwd

To create a user on the repository use, the following command:

sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd <username>

Note that you should only use the -c option the FIRST time that you create a user. After that you will only want to use the -m option, which specifies MD5 encryption of the password, but doesn't recreate the file.

Example:

sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd geek
New password:
Re-type new password:
Adding password for user geek

Restart apache by running the following command:

sudo /etc/init.d/apache2 restart

Now if you go in your browser to http://www.server.com/svn, you should see that the repository is enabled for anonymous read access, but commit access will require a username.

If you want to force all users to authenticate even for read access, add the following line right below the AuthUserFile line from above. Restart apache after changing this line.

Require valid-user

Now if you refresh your browser, you'll be prompted for your credentials:

You now have a working subversion server!

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 12/28/06 and tagged with: Ubuntu

Comments (29)

  1. Nick

    Thanks for the great guide!

    Make sure you set the permissions of the /svn directory to apache with the following command:

    sudo chown -R www-data:www-data /svn

    Nick

  2. Max Russell

    I actually set my Subversion directory up in my home directory, so it looks like:
    /home/max/Projects

    if I set the root directory from which Subversion can be accessed to /home/max/Projects, does this have any security implications for everything under the level of /home/max or will the browsable content when I get the subversion server hooked up to apache only be at the /Projects directory level?

  3. Philipp Keller

    Thanks a lot for this tutorial. Worked like a charm. You spared me some hours of figuring this out myself.

  4. Lane Roathe

    Thanks for the page. I wanted to add that if yo have a multi-repository setup you need to change

    SVNPath

    to

    SVNParentPath

    or you will not be able to get access to your repositories.

    I'm using a setup similar to Max's and have not seen any security implications so far, for what that's worh.

  5. calenti

    Thanks so much - I have spent two days trying to get AlephZero's version working and by following your instructions had it in 10 minutes.

    You aren't just the HowToGeek - you're the GoToGeek.

    Now can you tell me, is the Internet down? I tried to use my computer's cup holder and it broke, can you get me a new one?

    :)

  6. Lorin

    Thanks,

    Only thing I had to add was one line after the auth section:

    Require valid-user

    Else it doesn't prompt for a password. Other than that, this how-to was very straight-forward and concise. Three cheers for SVN! =)

  7. Francesco Montorsi

    Thanks for this great & simple guide!
    The only thing I had to change was "htpasswd2″ in "htpasswd" which is part of the "apache2-utils" package in my Gutsy install.

  8. Jörg

    Hallo & Thanks for this very good instruction. As mentined before by another one, after spending a lt of time in get things work, your explaination helped me to get it work in a few minutes.

    But one point differs in my Kubuntu 7.04 instalation. i only had htpasswd instead of htpasswd2 and i could not
    install another version !?! - But it works :-) )

  9. Katrin

    cool - that went smoothly :)
    thank you.

  10. lautaro

    This works pretty well, thanks allot.
    The only problem that I had, was the command:
    "htpasswd2″, I solved it changed it by "htpasswd"

    Cheers

  11. Zeev Russak

    Please remember to uncomment the tag at the end of the configuration file.

  12. Eddy

    Hi, I've setup a subversion based on the above tutorial but honestly I am a little lost. My situation is that I would have a subversion and a couple of clients within LAN. Is that possible, let's say the subversion server is at address 192.168.100.100 while other clients are at 192.168.100~105.

    The error message I received when connecting client to svn server was "Error * can't connect to host '192.168.100.100′: No connection could be made because the target machine actively refused it.

    I am running ubuntu 7.10.

  13. Shan

    Very good instruction.

    Thanks!

  14. Sanj

    Thanks mate, good one! :)

  15. Sanj

    @Eddy, can you connect to the server from locally from the server (as opposed to remotely from another computer)? You may have a firewall running which could prevent external access.

    You could also do a [sudo netstat -an | grep ':80′] to make sure you apache2 server is up.
    Make sure it is in LISTEN mode. If you're running on another port, substitute the 80 with that port. To find out which port you are running apache2 on you can use [cat /etc/apache2/ports.conf]

    to start the apache2 server manually run [sudo /etc/init.d/apache2 restart]

  16. Neuquino

    How can I hide the version of subversion? I mean, that line: "Powered by Subversion version 1.3.2 (r19776)"
    That line has some security issues that I don't want to deal with.
    Thanks
    Neuquino

  17. Tim

    I had to use htpasswd for this all to work on my ubuntu gutsy gibbon box.

  18. Albo

    Wow.. I did this in Windows and took me half hour, here in ubuntu just did in 5 minutes.
    I used htpasswd too, and I forget to uncomment .

    Muchas gracias!

  19. arbingersys

    Excellent article and instructions. Got SVN up and running on a fresh server in no time.

  20. andrea

    hi , tanks for article!
    but
    authentication seem not work for me. i have follow the guide but if i try from remote machine

    >svn co http://myServer/svn
    >cd svn
    >touch test
    >svn add test
    >svn commit

    it let's my do without ask for a password.
    i want commit acces require username/password.
    how can i do?

    someone could suggest me a good web tracking/ticket sistem?

    sorry for my english.
    tanks
    Andrea

  21. Brian

    I am having 403 forbidden errors… kUbuntu 7.10
    http://www.pastebin.ca/994167

    any idea's? thanks…

  22. Vinidog

    I'm with the follow erros:

    sudo /etc/init.d/apache2 restart
    * Restarting web server apache2 Syntax error on line 16 of /etc/apache2/mods-enabled/dav_svn.conf:
    DAV not allowed here

  23. Raptor Ramjet

    Under Ubuntu Hardy Heron (8.04) the command "htpasswd2″ seems to now be named "htpasswd" so the line should now read:

    sudo htpasswd -cm /etc/apache2/dav_svn.passwd

    After a quick 10 minute googling that worked for me.

  24. anon

    You realize that this is completely plain text, don't you? Set up SSL.

  25. Raptor Ramjet

    Vinidog,

    Your problem is probably that the "" and "" directives are commented out. Remove the"#" at the start of the lines and it should work (I had the same problem)

    And I didn't spot lautaros post when I added my tip yesterday… Ho hum…

  26. wildduck

    If you get this error when trying to import your projects from remote locations:

    svn: Can't create directory '/srv/svn/projZ/db/transactions/0-1.txn': Permission denied

    you need to allow import through http access:
    chown apache:apache -R /path/to/repo

    in ubuntu its
    chown www-data:www-data -R /path/to/repo

  27. Sayali

    Thanks for the wonderful guide!
    One observation: when using
    sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd
    I encountered an error that I dont have htpasswd2. So I used htpasswd instead and everything else worked fine!
    Thanks again!
    – Sayali

  28. ramesh

    i have a subversion in ubuntu.please give the detail to install and configuration.

  29. Tarun

    Thanks for your instructions. Help me alot. but one confusion. what to do if i need to refer the domain like "http://svn.localhost"


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Sponsored Links
Getting Started
About How-To Geek
Popular Articles

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.