Subversion
From DreamHost
We are hoping to create articles that meet certain standards. Please discuss this issue on the talk page. Editing help is available.
Subversion (official site) is a version-control system that keeps track of changes in your files on a server. Subversion helps to coordinate work among multiple people. For an introduction - read the book - it is really great.
[edit] Subversion on Dreamhost
The current version of Subversion on Dreamhost is 1.4.2. If you want to install a newer version, please see Subversion_Installation. If your server is still running old 1.3.x version, let us know and we can upgrade it for you. Subversion 1.4.x features repository mirroring, more efficient transfer and storage of binary files in comparison with previous versions.
You can install and configure Subversion repositories from control panel.
[edit] Quick Start
To set up a Subversion repository at svn.yoursite.com for a project called "myproject", follow these steps:
- Create svn.yoursite.com:
- Go to your DreamHost control panel and click Domains, then Manage Domains
- Click Add New Domain / Sub-Domain
- Enter "svn.yoursite.com" in the Domain To Host field, enter "svn.yoursite.com" in the Web Directory field, and select Remove www.
- Click Fully Host This Domain Now!
- Wait a few hours until the new DNS information propagates (that is, when visiting svn.yoursite.com in a web browser doesn't give an error--the page will look like an empty directory listing once the DNS info has propagated).
- Set up a Subversion repository:
- Click Goodies, then Subversion
- Enter "My Project" in the Project Name field, "myproject" in the Project ID field, and make sure that svn.yoursite.com is selected for the URL. Use "myproject" as the directory name.
- Replace the dummy usernames and passwords with a username and password for yourself.
- Click Create My New Project Repository Now!
As soon as the DreamHost Subversive Robot actually creates your repository, you can begin using it. For instance, to import a directory:
- svn import some_directory http://svn.yoursite.com/myproject -m "Initial import"
You can create additional users for your Subversion project at any time by going to Goodies, Subversion and editing the project. Using this method, users cannot change their own passwords.
[edit] Gotchas
Warning: If you create a new repository at an existing domain, the domain may be moved to a new Apache service and the DNS information will change. This will affect you if you have your DNS info hosted somewhere else than Dreamhost (you'll have to get the new IP address and update your DNS info). This is only the case with domains that have been hosted with DreamHost for more than a year or so. Anything added more recently than that will probably not be affected.
Warning: Repositories don't act like normal directories: You will not be able to use .htaccess files, cgi scripts, etc. in your repository directory. For instance, if you setup your repository at http://svn.example.com/, you will not be able to password protect that directory using .htaccess. You must use the Public/Private field in the Subversion panel page. Changes made in the Htaccess/WebDAV panel also do not apply to your SVN repository.
This also means you can't install ViewVC in the main repository directory. To work around this, put your repository in http://svn.example.com/svn/ and the ViewVC cgi in http://svn.example.com/. Remember, you'll need to use a .htaccess file to configure http://svn.example.com/, but the Public/Private field in the Subversion panel to protect http://svn.example.com/svn/.
Hastily-made repositories often don't work: If you create your repository before its intended host is fully created (and resolved), you may have an inaccessible repository. Assuming it doesn't yet contain any information (how could it?), just delete it and recreate it. (Alternatively, you may be experiencing a DNS propagation delay if you can access your repository via http within the DreamHost system, but see an empty directory from outside DreamHost [Apache 1.3x serving your empty domain]. If you can't wait, try querying the DH DNS servers for your IP and using a local hosts file or NetInfo to temporarily resolve your svn host. Remember to undo this when DNS records have propagated.)
Some have reported success just submitting an edit (with no changes) to their repository in the Control Panel. This operation recreates your reponame.access and reponame.passwd files re-establishing dhapache as their group (and undoing any MD5 passwords you've made manually). Unfortunately, this does nothing to fix your repository if the owner has been changed from dhapache to your username.
It would be nice if the Subversion Control Panel had an explicit option to fix owner and group on a given repository, say, by running:
sudo chown -R dhapache ~/svn/reponame; sudo chgrp dhapache ~/svn/reponame.access ~/svn/reponame.passwd;
... in the background. As it is, you have to dump, recreate and reload your repository.
Another nice feature would be a Control Panel switch to allow passwords to be created and maintained with MD5 encryption.
Some clients require MD5 passwords: If you get "access denied" warnings, you may need to use MD5 passwords instead of the standard variety created by the DreamHost Control Panel. Use htpasswd -nm username to generate the entry (ala username:passwd-hash) for your reponame.passwd file. And use an editor (ala nano reponame.passwd) to replace your standard password entry.
Don't overwrite your reponame.access and reponame.passwd files with echo "username:passwd-hash" > reponame.passwd Overwriting the files will cause them to have your user's group instead of dhapache, leaving your repository in a read-only or inaccessible state.
Removing repositories through the control panel doesn't seem to remove the ~/svn/<repo-id> directory. (as of Apr 12 2006) Workaround:
cd ~/svn; mkdir old; mv <repo-id> old
You have the proper permissions to do this. (You can also use WebFTP to delete or rename the repository directory.)
[edit] Connecting to Subversion Repository
[edit] Using svn+ssh
Allows for a svn client to connect directly with the repository via ssh.
You have to set up a ssh username and password. Subversion users defined in the panel will not be used for authentication.
svn+ssh://{user}@www.yourdomain.ext/home/{user}/svn/{project}
note: {project} is the ID of your subversion project, NOT the projectname.
You should also check SSH#Passwordless_Login to use this mode without being asked for the password repeated times
See also SVN book for SSH tricks
[edit] Using HTTP
- Use the HTTP path that you used in the Subversion panel.
- Sign in using username and password specified in the panel.
- Is there any way for svn users to change their password in this mode? No. Only through panel.
- Is there any way to use https instead of http? Yes, but first you will need a unique IP address and Secure Server installed on your domain.
[edit] Using the Command Line (CLI)
- Locally (assuming your project is hosted on Dreamhost and can be accessed from your shell).
svn list file:///home/{user}/svn/{project}
- HTTP.
svn list {projectURL}
- SSH Tunnel.
svn list svn+ssh://{user}@www.yourdomain.ext/home/{user}/svn/{project}
note: {project} is the ID of your subversion project, NOT the projectname, which can be found on the Subversion panel.
note: {projectURL} is the Project URL chosen by you on the Subversion panel.
[edit] How to use: quick reference
| The instructions provided in this article or section require shell access unless otherwise stated. You can use the PuTTY client on Windows, or SSH on UNIX and UNIX-like systems such as Linux or Mac OS X. |
[edit] Creating Repository via Command-Line
If you didn't use the Dreamhost Subversion Panel, you can create the repository at a directory. If you used the Quick Start method then skip this step and go to the next one.
svnadmin create /home/user/path/to/repository
[edit] Gotchas
Handmade repos are read-only (via http): If you find that you have to tweak and reload your dumpfile a few times, it can be handy to use the CLI tools (e.g. rm -rf and svnadmin create) to wipe and recreate your repository until you get it right. But then you'll want to use the Control Panel to delete and recreate your repository. Your test repositories will not function properly in production (they won't permit any changes).
The Panel creates the repository with dhapache as the owner, and the reponame.access and reponame.passwd files with dhapache as the group. Trying to create your own production repo with svnadmin create is futile because you don't have authorization to change those ownerships and group memberships (and you're not a sudoer).
Don't overwrite dhapache files: Don't overwrite your reponame.access and reponame.passwd files with echo "username:passwd-hash" > reponame.passwd (e.g. if you're trying to use MD5 passwords). Use an editor and paste in the new data. Overwriting the files will cause them to have your user's group instead of dhapache. If your repository is relatively mature when you make this mistake, and you have no backup, you will be out of options.
[edit] Importing Folders and Files
Once the repository is created you can add folders and files that you have in another location. It is better to use this method to keep the revisions number down when first creating the repository.
svn import /home/USER/path/to/source file:///home/USER/path/to/repository --message="Importing Project"
You have to put a message in and change the text inside to whatever you are doing at the time.
[edit] Loading a dumpfile
Sometimes, you would have an existing repository that you want to migrate to your Dreamhost svn repository. You will need to take a dump of your existing repository and load it into your Dreamhost repository.
- Dump your existing repository
svnadmin dump path-to-repo | gzip > dumpfile.gz
- Upload dumpfile.gz to your home directory.
- Load this into your repository.
- If you set up using the Dreamhost Subversion Panel, then the repository will be under the $HOME/svn/{repo-id} where the repo-id is the id you used to setup the repository in the panel. Decompress the dumpfile first.
gunzip -c dumpfile.gz | svnadmin load /home/USER/path/to/repository
Command should show all files being imported, if not then check the instructions and try again.
[edit] Using TortoiseSVN
TortoiseSVN is a Windows GUI integration program for svn. Use at your own risk and is not officially supported.
This walkthrough assumes username is myname, with a website at www.mysite.com, and that the repositories are in ~/svn starting with a project named myproject. You can choose your own directory names.
Step 1: Create the repository following the Repository section of this guide. Step 2: Download and install SVN client
[edit] Create Session Key
If you don't create the public session key, you will have to type your password in for every action in the browser and for every time TortoiseSVN connects to the server.
Start in your home directory
cd ~
Generate the key set using the passphrase of your choice and put the public key in a .ssh directory (note: the name "rsakey" isn't required)
Write down your passphrase as you will need it later.
ssh-keygen -b 1024 -t rsa -N SomeLongTextForPassphrase -f rsakey
Create the .ssh folder
mkdir .ssh
Move the public key inside of the folder and rename it.
mv rsakey.pub .ssh/authorized_keys
Change permissions on both the folder and file for security.
chmod 700 .ssh chmod 600 .ssh/authorized_keys
Download and install the Putty tools (scroll down to the Windows-style installer). This is an SSH client with authentication tools.
Download your "rsakey" file (your private key) from the server to your local machine (the rsakey should be in your home directory).
Use your Windows FTP client.
Load it into the PuTTYgen tool (puttygen.exe) and enter your passphrase when it asks for it.
Use SSH-2 (RSA) which will be the default.
Save it as a private key from PuTTYgen in a safe place as rsakey.ppk.
[edit] Setup New Session
- Run PuTTY Pageant. Pageant will put an icon of a computer wearing a hat into the System tray.
- Load a private key into it. Double click on the icon and then click on Private Key File.
- Type in the Passphrase.
- Run Putty and make a new session:
- Hostname: www.mysite.com
- Protocol: SSH
- Saved Sessions: mysiteSSH
- Connection->Data->auto-login username: myuser
- Connection->SSH->preferred protocol: 2
- Connection->SSH->Auth->private key file: path\to\rsakey.ppk
- Click "Save" on the sessions panel to save this config.
- Open PuTTY if you want to test your session. PuTTY will notice that Pageant is running, retrieve the key automatically from Pageant, and use it to authenticate. You can now open as many PuTTY sessions as you like without having to type your passphrase again. You may get a message saying, "The server's host key is not set in the registry." (Insert what this means here.)
- Now find your local project directory, and copy what you want to add to Subversion into a temporary directory (let's call it "ImportMe"), organizing it carefully -- it's smart to put your files in a "trunk" directory so that working with new branches and tags later is simple.
- Right-click on the ImportMe folder and select "Import..." from the TortoiseSVN submenu. You will be adding everything inside this folder into the root of the "myproject" repository.
- In the import dialog, enter the URL of Repository like this. Replace "mysiteSSH" with the name of your PuTTY stored session and "myusername" with your real username. If you just want a straight SSH tunnel, we'd use myuser@www.mysite.com here instead of mysiteSSH:
svn+ssh://mysiteSSH/home/myusername/svn/myproject
...and click "Okay". This will load your project files into the repository.
- Next, check out the files you want to work with into your project directory (but make sure you aren't overwriting files when you check out or you'll get errors). This is the "SVN Checkout..." option in the folder context menu.
Everything should be pretty self-explanatory from there on.
[edit] Other References
[1] - For Windows XP
[2] - Guide from TortoiseSVN site (generate RSA key instead of DSA key).
[edit] Notes
- TortoiseSVN (1.1.3) - Go into Settings and enter TortoisePlink as the SSH client under the Network tab to connect to your repository. You can use svn+ssh://myusername@mysiteSSH/home/myusername/svn/myproject to specify your username directly in the URL. Along with Pageant for key-based authentication, using TortoiseSVN is very transparent and easy to use.
Also screen is getting over worked for overnight checkouts (yes overnight)
screen svn co &> ~/log_co & ^ad
[edit] Multiple User Access to Repository
(I have only tried this in a bundy shell, not externally (with TortoiseSVN, for example)
- Create at least two users (mysvnadmin, mysvnuser)
- Create the repository and import the project with mysvnuser.
- Login (ssh) to mysvnuser's account:
$ su mysvnuser $ svn co file:///home/mysvnadmin/repos/project work $ svn add file $ svn commit -m "added file" $ svn log r1 | mysvnadmin | 2005-09-04 08:03:47 -0700 (04 Sep 2005) | 1 line initial import r2 | mysvnuser | 2005-09-04 23:34:13 -0700 (04 Oct 2005) | 1 line added file
I had no trouble with svn+shh (on bundy):
$ svn co svn+ssh://mysvnuser@bundy.dreamhost.com/home/mysvnadmin/repos/project work
Note: The mysvnadmin user must have "Enhanced Security" turned off in order to share data between the two users. There is a checkbox on the User setup screen (under Manage Users) that allows you to toggle enhanced security.
[edit] Using Apache basic authentication
The Dreamhost panel provides a way to create user accounts only for Subversion- the above steps require each user to have a Unix account with shell access so they can log in via SSH.
If you want to do per-directory permissions in your repository using those accounts, you need to manually edit the .access file as described here:
However, if you make changes to the user list using the Dreamhost control panel, it will overwrite any changes you make to the .access file.
You can manually add and administer the usernames and passwords for Subversion by using htpasswd to add/edit users to the .passwd file for your repository. This is not recommended though, because after manual editing either the .access or .passwd files, the group changes from dhapache to whatever the auto-generated group for your account is. This prevents the Apache module from being able to read the files. You then need to change the permissions so that they can be read by apache: chmod 644
Note that this is giving "world" read access to those files, which potentially is a security risk. Using control panel automatically resets group back to dbapache, but you will lose your per-directory settings. Using Apache and these passwords isn't very secure anyway without https access, so this is all more for convenience. If you need security, create Unix accounts with SSH shell access as described above.
[edit] Using Subversion for Web development
[edit] Using Your Repository (via Command Line)
Now that you imported your files to the Repository, you might be wondering how to leverage version control to your advantage. First thing you need to do (if you haven't set it up already) is set up a Development area and a Live area. For the purposes of this HowTo, http://svn. http://dev.yoursite.com/ will be our development area and http://www.yoursite.com will be the Live area.
1 ssh into your Dreamhost account. From your home directory, we'll be issuing the following commands. 'svn help' can be very useful.
2 Back-up your site
tar -cvvf yoursite.tar yoursite.com/
3 Check out your repository to your development area
svn checkout http://svn.yoursite.com/yourProject dev.yoursite.com
4 Check out your repository to your live area
svn checkout http://svn.yoursite.com/yourProject yoursite.com rm -rf yoursite.com mkdir yoursite.com svn checkout http://svn.yoursite.com/yourProject yoursite.com
Note: If the yoursite.com directory is the directory you initially imported from, you may get errors. I recommend starting from scratch (why I had you back up the site to begin with)
[edit] Publishing from Dev to Live
All the changes you made in your Dev area are now ready to go Live.
1 Go to your dev directory
cd dev.yoursite.com
2 Commit your changes
svn commit -m "Your change log notes"
3 Go to your live directory
cd ~/yoursite.com
4 Update Live
svn update
[edit] Automatic Post-commit Checkout
Subversion can be a very useful tool for developing Web sites or Web-based applications. You may wonder, though, how that would work. After you commit your changes to your repository, how do you have them reflected on your site? The easiest method is to have your site's directory on the server be a working copy checked out from your Subversion repository. If you elect to do this be certain to modify your site's .htaccess to prevent users from browsing Subversion's control files. Something simple in the root of your site such as the following will suffice.
RedirectMatch 403 /\.svn.*$
Additionally you can configure your site to automatically check out the current sources from your repository by using Subversion's "hook scripts". In short, the script called hooks/post-commit will be executed by the web server each time new sources are checked into your repository. Be advised that when the web server executes this script it is running in the security context of the dhapache user -- this user does not and should not (for security reasons) have the necessary permissions to modify the files in your web site's directory. As such we need to arrange for the post-commit script to run the update in the security context of a user with the privileges necessary to update your site.
Users familiar with UNIX systems will recognize that this is a task for a setuid binary. Unfortunately the DreamHost /home/ directories are NFS filesystems which are, for security reasons, mounted with setuid disabled. Fortunately the workaround is trivial -- simply set up your update script as a CGI script and have the Subversion post-commit hook invoke this script. Instructions follow.
1. Create a private directory on your website to host your updater script such as /home/username/mysite.com/cgi-bin/pri
2. Secure the private directory by creating a .htaccess file with contents similar to the following.
AuthName "Dialog prompt" AuthType Basic AuthUserFile /home/username/mysite.com/cgi-bin/pri/.htpasswd Require valid-user
3. Using the htpasswd utility create the .htpasswd file by running the following command in your /home/username/mysite.com/cgi-bin/pri directory. For security reasons make up a new username and password and do not re-use the username and password of a user you have created on your server or a user you have given access to your subversion repository.
htpasswd -bc .htpasswd someuser somepasswd
4. Now that you have created and secured a directory for this special CGI script to live in, create a script in that directory called do_update.cgi with the following contents.
#!/bin/bash set -f echo Content-type: text/plain echo echo "---++Synchronizing site to the latest copy in subversion++---" /usr/bin/svn update /home/username/mysite.com
4b. Don't forget to give execution privilege to your file.
chmod +x do_update.cgi
5. Finally, modify your /home/username/svn/projectname/post-commit to invoke your CGI script so your site will update after each commit.
#!/bin/bash wget --http-user=someuser --http-passwd=somepasswd -O - http://mysite.com/cgi-bin/pri/do_update.cgi
[edit] Upgrading to Newest Subversion
If you would like to install a newer version of subversion (e.g., for repository syncing), then you will need to go to this page
http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=260&expandFolder=74
and download both the subversion-x.x.x.tar.bz2 and the subversion-deps-x.x.x.tar.bz2. The "deps" file contains all the subversion dependencies.
The newest subversion as of 2007.03.12 is 1.4.3. To install locally, create a temporary work directory and do the following.
mkdir tmpwork cd tmpwork wget http://subversion.tigris.org/downloads/subversion-1.4.3.tar.bz2 wget http://subversion.tigris.org/downloads/subversion-deps-1.4.3.tar.bz2 tar -xjf subversion-1.4.3.tar.bz2 tar -xjf subversion-deps-1.4.3.tar.bz2 cd subversion-1.4.3 ./configure --prefix=/home/{yourlogin} --with-ssl make make install
That will install the new subversion into your user directory. You'll need to change the path to include your ~/bin directory to use the new binaries.
[edit] Interfacing with Subversion from PHP
You'll need to install the PECL extension SVN. Detailed instructions are available here: http://hp.jpsband.org/xhtml-compiler/docs/compile-svn.txt
[edit] Setting up post commit emails
Simply edit your svn/(repository name)/hooks/post-commit.tmpl file. Change /usr/lib/subversion/hook-scripts/commit-email.pl "$REPOS" "$REV" something@example.org to your commit email list. Then reinitialize SVN.
The actual file should be post-commit, not post-commit.tmpl. If you use an editor that edits in place, as opposed to (for instance) emacs which moves the original aside and creates a fresh file, you should still have the right owner/group and not need any reinitializing.
The default settings for commit-email.pl may be to use a connection to localhost instead of firing up sendmail, in which case you need the --from parameter for bounce/envelope address.
It appears that the post-commit script won't run unless it's owned by the user (not dhapache) and set to world-execute.
[edit] External Links
[edit] Books and tutorials
Version Control with Subversion is the Online Subversion book freely available online in its entirety. If you have shared hosting, focus on the file:// and svn+ssh:// protocols (which do not involve any actual continually running "server" processes that might not be good in a shared environment). If you have a dedicated hosting, you can do whatever you want I imagine.
[edit] GUI Integration
- SCPlugin is a Finder contextual menu plugin for Mac OS X for subversion operations. Windows users will recognize it as the Mac analogue to TortoiseSVN.
- <oXygen/> SVN Client Requires paid registration after 60 day trial.
- SvnX is an excellent GUI for Mac OS X.
- TortoiseSVN is a subversion client implemented as a Windows shell extension.
- RapidSVN Multi-platform GUI for Mac OS X, Linux, Windows.
- Syncro SVN Client a cross platform Subversion client.
[edit] Web-based repository browsers
These provide a number of convenient features, including RSS feeds, integrated bug tracking, collaborative documentation:
- Warehouse - Rails based
- Trac (Difficult Installation)
- ViewVC formerly ViewCVS official site, old site
- WebSVN - auto-tarball of directories, syntax highlighting - official site
- SVN::Web - on CPAN

