Howto use subversion to manage a website

Copyright Randy Melton Sep 2006



My Reasons for useing subversion to manage a website

I've write many of my pages by hand in html format. I wanted a way to work on pages in progress and only publish them when I'm ready. I often use different computers to do this editing. My first solution was to keep the files on a USB memory stick and upload them (rsync and ssh) when I was ready. This worked pretty well, but sometimes I wanted to add something and didn't have the memory stick with me.

I tried some of the content management systems. These had the advantage of letting me edit my pages from any machine, but I wasn't happy with the style and worried about the security in the systems as well as recovering old versions. I'm sure there are some good tools there, but I was looking for something simpler.

I already use subversion for several other projects so I know it pretty well. My hosting company (nearlyfreespeech.net) allows svn+ssh so I gave it a try and liked it. Since it isn't obvious how to do this I wrote up these instructions for anyone that wants to do the same.

These directions are written assuming you are using nearlyfreespeech.net, but should work on any host that allows ssh access and has svn installed.

The mysite example

Assumptions

  1. Site name is mysite
  2. The site username is myusername
  3. The site password is mypassword
  4. The ssh machine name is ssh.phx.nearlyfreespeech.net
  5. You will be working in mylocaldir on your local system (my mac)
  6. Your hosted home directory tree looks like this:
        /home/
           htdocs/   <-- This is the top directory of your website
           private/  <-- This is a directory where you can store private files
              svn/   <-- this will get created when you init the svn repository (name is arbitrary)
        

Prerequisites

  1. You have a hosting company that allows ssh access to your user account
  2. You have a svn client installed on your local machine
    (I installed it from ?? on my mac OS X 10.3.9)
  3. You havs a ssh client installed on your local machine
    (my mac OS X 10.3.9 had it installed)

Creating the repository

ssh myusername_mysite@ssh.phx.nearlyfreespeech.net
export EDITOR=nano
svnadmin create /home/private/svn
svn mkdir file:///home/private/svn/htdocs -m "create directory for new project"
svn mkdir file:///home/private/svn/htdocs/trunk -m "create new driectory for trunk"

Fixing the server htdocs dir to pull from svn

(next steps will set up the htdcs directory on the server as a svn sandbox)
svn co file:///home/private/svn/htdocs ./tmp
mv ./tmp/trunk/.svn /home/htdocs/

Checking out a copy on my mac

(must be run from a terminal window)
svn co svn+ssh://myusername_mysite@ssh.phx.nearlyfreespeech.net/home/private/svn/htdocs/trunk ./mysite.com

Adding new fies

create the new file (copy it in, create in a editor, whatever...)
svn add newfile
(You must "commit" to get the repository updated)
(You must uodate the web site after the commit so it gets the new file)

Committing the changes to subversion

(from the top of your project directory on your local system)
svn status                           (This will tell you what you have changed)
svn commit -m "Reason for commit"    (you should explain the reason for the changes here)
(Remember, the web site must be upodated before it gets this new revision)

Updating the website

ssh myusername@ssh.nearlyfreespeech.net "cd /home/htdocs ; svn up"
(You will be prompted for your ssh password.)

Updating the copy on my mac

cd localtop
svn up

Further steps

  1. You can edit file on your local system (use svn add to add new files)
  2. use svn commit from the top (project) dir to send your changes to the server
  3. Use svn up to bring whatever system/directoru you are in up to date.

References

  1. subversion software -
  2. subversion book - (free online copy @ http://svnbook.red-bean.com/ or buy a copy from amazon from this link and I'll make a few cents on the referral)


Google
email any comments to: