Article
Harness the Power of CVS for Your Site
Hugging the Tree
Right. Enough talk: it's time to throw you right in at the deep end! We're going to install a CVS client and check out a repository to our hard disk. For this example you'll need to be running any version of Windows.
The Big Install
CVS is sounding pretty serious right? So you imagine it's gonna be really hard to install the client? Well, brace yourself...
- Head to cvshome Windows downloads and click on the Win32 link (below the word "Platform"). Save the ZIP somewhere on your hard disk.
- - Now extract the file (cvs.exe) to your Windows "system32" directory (usually c:\windows\system32\)
That's it: installation over! Well... almost. We've installed the DOS command line CVS client, which gives you a simple interface to CVS that you can use straight away.
But let's not stop there -- seize the moment and check out your first CVS repository! We're going to check out the PHP source code for phpBB2. phpBB is an Open Source project hosted at Sourceforge, as your can see here. And because it's Sourceforge, everyone has anonymous (read only) access to the projects CVS tree. The details of the phpBB tree can be found here, and if you click on "Browse CVS Repository" you'll see there are in fact two repositories: phpBB for the old version 1 of the code, and phpBB2 for the latest version. So let's (literally) check it out...
Open up an MS DOS prompt (usually somewhere on your start menu, perhaps in "Accessories") and type the following. Note that you'll need to be connected to the Internet for this to work:
cd \
mkdir cvs_root
cd cvs_root
cvs -d:pserver:anonymous@cvs.phpbb.sourceforge.net:/cvsroot/phpbb login
cvs -z3 -d:pserver:anonymous@cvs.phpbb.sourceforge.net:/cvsroot/phpbb
co phpBB2
Here's what we just did, line by line:
- [c]hange [d]irectory to the "root" of your c: drive
- [m]a[k]e a [dir]ectory called cvs_root
- Change to the cvs_root directory
- Login to the phpBB cvs rver - just press return when it asks you for a password
- Check out (co) the phpBB2 code - this is cAsE sEnSiTive, so be careful!
A list of files appears -- these are being copied to your hard disk. Each entry in the list looks something like this:
U phpBB2/common.php
The U stands for "Updating" and what that's saying is that it's checking out the file from the phpBB2 repository, and as a quick examination of your hard disk revealed no existing version of common.php, it's creating one in c:\cvs_root\phpBB2
Now if you look in the c:\cvs_root (you may prefer to do this part in Windows Explorer) you'll find a subdirectory called phpBB2 that contains all the latest phpBB2 code. Congratulations! You've just checked out your first CVS repository!
Now, for the next trick. Using your preferred text editor, open the file c:\cvs_root\phpBB2\common.php and right at the top of the file enter "This is a test", then save the file under the same name, and close it. Also, just for fun, delete the file c:\cvs_root\phpBB2\install.php
Next, back at your MS DOS prompt, type this from the c:\cvs_root directory (type cd if you're uncertain where you are):
cvs -z3 -d:pserver:anonymous@cvs.phpbb.sourceforge.net:/
cvsroot/phpbb update phpBB2
This time you'll see more or less the same thing as you did before when you checked out the repository, but with some subtle differences.
M phpBB2/common.php
The M says the file CVS found on your hard disk is different to the one in the CVS repository, so it will be left untouched.
U phpBB2/install.php
CVS couldn't find install.php so it reports that it's creating one.
Then the rest looks like this:
cvs server: Updating phpBB/admin
This tells you that the file found on your hard disk was the same as the revision in the CVS repository.
No go to your text editor again, and open up c:\cvs_root\phpBB2\common.php -- is your little message still at the top of the file? Yes it is!
Then in Windows Explorer (or otherwise) and look in the c:\cvs_root\phpBB2\ directory -- can you see install.php? Yes you can. It's back, even though you deleted it.
That's it! You just performed your first update! Now you've seen it in action, remember the "direction" in which updates work. "Update" is for updating your own working copy of a project on your own computer, from the CVS repository. To "update" the repository itself with work you've done on your computer, you perform a commit, which we'll look into later.
Starting to get a warm feeling yet?
Even with anonymous read-only access, we've got a very powerful tool at our disposal. Take the phpBB project, for example. For a standard installation you'd have only updated the file phpBB2/config.php with the local settings for your MySQL server etc. But, thanks to CVS, you can keep pace with the latest phpBB2 code using the update we did above, while keeping your local settings in config.php in tact. You can install phpBB2 on your site and update it on a regular basis, without ever having to bat an eyelid.
Translate that to updating your live Website. You and a team of developers perform a major overhaul of your site, changing hundreds of files. You do all the work away from your live site, leaving the old work there untouched. Once you're entirely happy with the new version, you login to your live Website and use CVS to update it with all the new work in a matter of minutes -- the major overhaul took your live site down for no more than five minutes! So see what a typical site owner thought about the ease and simplicity of using CVS on their Website, try this article.
The CVS client we installed was the command line version for DOS. But if you're not into command lines, don't despair! There's a GUI version called WinCVS (or sometimes cvsgui), which you can download here for Windows, Macintosh and GTK (GTK is for those Linux fiends -- though of course they probaly already know all about CVS). Installing the WinCVS client can be a little more tricky, so I'll leave the explanation of installation and usage to the documentation.
CVS has a number of authentication mechanisms. In the above example, we used the pserver method (Password Authentication Server). This is fine for anonymous access, but, like ftp, it sends your username and password in clear text over the Internet -- anyone with a sniffer who happens to be listening can steal them. For security's sake, you'll generally use ssh (secure shell) to access a CVS repository over the Internet for anything more serious than read-only access. Windows and Mac users should take look at the WinCVS-SSH-Guide for more about this.