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. This article was written on 12/28/06 and tagged with: Ubuntu

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:
Similar Articles Featured Wiki Articles
Latest Software Reviews Quick Linux Tips
Geek Arcade Popular Forum Threads

Comments (54)

  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”

  30. sooraj

    This was useful. I could setup the server in less than 10 min on an ubuntu box. The only thing missing was setting the ownership and permissions for the repository directory. I had to find that information from here: https://help.ubuntu.com/community/Subversion

  31. Christoph

    Thx for this short and helpfull howto. Works like a charme. As mentioned somewhere above, it is worth showing how to setup multiple repositorys in dav_svn.conf

    But thx a million

    /cheers Christoph

  32. Chris

    i have spent since tuesday morning trying to do the same thing on the spare mac we use as a server (OSX), got fed up and decided to try it on my linux machine that i work on…. done in 10 mins

    so come monday going to be talking my boss into getting a spare machine I can stick ubuntu on :D

    thx dude

  33. Jeff

    Thanks a bunch for this how-to, it really helped. All of the user comments on extras helped as well, so a thanks to them as well.

    If I might add a piece. Be sure to uncomment the following line at the end of /etc/apache2/mods-enabled/dav_svn.conf :

    #

    If you don’t uncomment it, you get the following error:

    apache2: Syntax error on line 186 of /etc/apache2/apache2.conf: Syntax error on line 13 of /etc/apache2/mods-enabled/dav_svn.conf: /etc/apache2/mods-enabled/dav_svn.conf:13: /svn/ was not closed.

    Thanks again!

  34. Lars

    If you’re getting an xml error messge – try chaing SVNpath to SVNparentpath in the dav_svn.conf file. It helped me.

  35. Ted

    I’m getting this error when I try to restart apache:
    * Restarting web server apache2
    apache2: Syntax error on line 184 of /etc/apache2/apache2.conf: Syntax error on line 14 of /etc/apache2/mods-enabled/dav_svn.conf: /etc/apache2/mods-enabled/dav_svn.conf:14: was not closed.
    …fail!

    The lines that the msg is talking about are these:
    # …
    # URL controls how the repository appears to the outside world.
    # In this example clients access the repository as http://hostname/svn/
    # Note, a literal /svn should NOT exist in your document root.

    Any ideas on why it’s failing?

  36. Hektor

    Ted, I got the the same error.I’m sure you removed the # from the first instance of location
    #
    You may not have noticed the ending location tag at the end of the file
    #
    If you remove the # from this tag it should work for you.

    Great article. adding a comment about the second # tag would have made things clearer for me.

  37. Action

    Many thanks. Got there in the end.

  38. Ted

    Thanks! Removing the “#” front the closing tag at the bottom of the file did the trick.

  39. Ted

    I’ve got this working somewhat, but when I try to create a new directory in the repo, I get the message:

    “Can’t open activity db: APR does not understand this error code”

    Anybody have any idea why I’m getting this?

  40. Zack

    Hey, that all went smoothly except when I try to navigate to that URL, the 401 authorization fails…

  41. Pham

    @Ted: I also have the same problem with you. I don’t know why.

    “Can’t open activity db: APR does not understand this error code”

    Could anybody help us?

  42. Fabio

    I found that adding setting

    SVNListParentPath on

    helped with a

    You don’t have permission to access /svn

    error.

    Didn’t look into this any deeper, just my 2cts.

    Regards,
    Fabio

  43. John

    thanks for every one’s help. One thing I want to add is when restarting apache2 via:

    sudo /etc/init.d/apache2 restart

    and you get the error:

    * Restarting web server apache2
    Syntax error on line 16 of /etc/apache2/mods-enabled/dav_svn.conf:
    DAV not allowed here
    …fail!

    Make sure that you uncomment the very last line in the file: /etc/apache2/mods-enabled/dav_svn.conf
    That line is: #
    Remove the # and it should be:

    Save the file and restart apache2 again. It should work.

  44. John

    For some reason it did NOT pick up the line: It is the ” directive.

  45. eka

    i got this error when i access http://localhost/svn

    Could not open the requested SVN filesystem

    what should I do..?
    thx b4

  46. Ikonye Mwangi

    Thanks a lot for your tutorial. It really helped. Thanks to all those who dropped their comments. But it seems most guys(including me) are forgetting to remove the ‘#’ from ‘#’ closing tag and therefore getting errors. If possible include this in your tutorial.
    Thanks again.

    Regards GMwangi.

  47. Jagjot Singh

    Hi i could successfully install svn in ubuntu but opening the repo page in firefox 3 shows text instead of webpage. Where am i going wrong ?

  48. balcony

    Hi,
    My svn server already working but I can not do these following:

    1. auto checkout a folder with svn server every 5minutes
    2. View file uploaded to SVN server on computer that instal SVN server (view as my computer file on windows)

    Thanks for help

  49. Sourav Mohanty

    Thanks a lot for the reference. Great Post.

    Cheers,
    Sourav Mohanty (Linux Lingo)

  50. Yamin

    Thanks a lot, it worked for me. :)

  51. Ankur

    Even after 3 years, your process works flawlessly :) . Thanks!

  52. Mathan Kumar

    hi,

    Thanks for your tutorial. This helps me a lot……

  53. PhyloGenesis

    I was getting the Forbidden error, and when I added the ShowParentPath it worked, however I discovered you shouldn’t be using ParentPath if you did svnadmin create /svn. (Remove ShowParentPath if you added it.)
    What I wanted was multiple repos within /var/svn so I did:
    mkdir /var/svn
    svnadmin create /var/svn/repo1
    svnadmin create /var/svn/repo2
    then with SVNParentPath set to /var/svn, I couldn’t access http://IP/svn but I could access http://IP/svn/repo1

    So I think the problem is you are using SVNParentPath but have /svn as a repository itself rather than the parent directory of other repos.

    Hope that helps.
    PhyloGenesis

  54. Gene

    I found if the apache2 user is different from your svn root user, you will have problem to write to the svn repo. Anyway, I have to do: sudo chown www-data:www-data -R /svnroot. FYI.


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to 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
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
Cmd.exe
Dpupdchk.exe Adobe_Updater.exe

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