Note: this is one of a series of posts about the creation of the King Design web site.
The more I use Subversion (SVN), the more I like it. The initial ramp up to understanding how a source control system works (and how to work with it) is hard, but the benefits are definitely worth it. Luckily, I have an SVN guru friend who is amazingly patient with my many questions.
When developing web sites in the past, I’ve set up local versions that I then push to the live or staging server. I’m very diligent about updating the local version then copying that to the server… until the site is live. Once the site is live, I’ll be making edits from different computers, different operating systems, etc. and those changes almost never make it back to my local version. It’s a total mess and I’ve lost work because of it.
The King Design web site was the first web site I built since I started using SVN, and I found it to be an invaluable development tool. Here are some of the benefits and ways I used it to create the King Design web site:
- The main web site is a checkout of my kingdesign.net SVN repository. Changes I make on the server and changes I make on my local development copy can be checked in then distributed to the other checkouts. If I needed to test something live on the server, I’d edit the files over SFTP until I had them as I wanted, check them in, then SVN update on my local copy to grab the changes. SVN manages conflicts and versioning – one less thing for me to think about.
- The demo and trial installations of Tasks are also SVN checkouts. I created branches of Tasks Pro™ and Tasks where I made the changes needed for the demo and trial installations. Then I checked those branches out into the King Design site for the demo and trial installations. When I upgraded Tasks Pro™ to version 1.5.1 and Tasks to 2.5.1 this week, it was a piece of cake to update the online demos and trials – “svn update”.
- I do 90+% of my development on my PowerBook, and 90% of the testing I do on that development is done in Camino and Firefox. Once I have everything working as I want it to in a Gecko browser, I turn my attention to Safari and IE (Win). SVN made it much easier to make my IE specific changes. When doing my IE testing for the King Design site, I could edit and test directly from the PC then check in those changes and pull them back to the PowerBook and the remote server when they were ready.
- The most obvious benefit to a source control system is it gives you both a backup of your work and the ability to go back in time in case you screw something up or need to retrieve something you’ve lost. Luckily I didn’t need to do this while developing the King Design web site1, but it’s certainly comforting to know I could have.
- SVN (all source control really) allows you to create a snapshot of the site at a given time; this is called a “tag”. By creating tags at certain stages of development and as the site evolves, you can easily go back to a certain version of the site as needed.
- SVN (all source control really) also allow you to create “branches” where you can make experimental changes or work on new development that isn’t ready to go live yet. You can then check out your branch to a staging location for testing, etc. while the main site remains intact.
Branching and tagging are very basic and common practices in software development, but much less common in web site development. It’s hard to stress enough the benefit of having your web site under source control and being able to take advantage of all these capabilities.
Note: it’s a good idea to deny access to .svn directories on your web server if you are doing SVN checkouts to your webserver. If you’re using Apache, you can add this to your httpd.conf or .htaccess file:
<Directory ~ "\.svn">
Deny from all
- I have had to do this with client web sites from time to time – thank goodness for source control! [back]
SVN As A Web Site Maintenance Tool
Alex King writes about his experiences using the Subversion Version Control tool to manage his web content for alexking.org.
How do you handle .htaccess files in repository?
For example in developer version .htaccess file will have such line:
But on live server this line must be replaced with:
Thanks for the reply
I haven’t actually had a problem with this – I’m not sure why.
nice write-ups. i’ve been doing much the same process as of late.
one tip: use the “svn export” command to push a ‘clean’ copy of your work live–it leaves out all the .svn files and folders.
If you svn export then you can’t commit changes from the live site back to the repository.
I sometimes run into that problem, and if you’re on a system that allows symbolic links (about any unix will do) you can set it up like this:
create two files:
and put them both in your versioning system
now make a symbolic link (do _not_ put this in your versioning system)
.htaccess -> .htaccess-dev
on the dev server, and another to the live version on the live server.
Another option: create a branch for de dev version and put a different .htaccess there — this might be a bit more complex to understand though, and you wont have easy access to the live version on dev, and the other way around.
[…] SVN as a Web Site Maintenance ToolÂ – Alex King Tips for using subversion to run a web site […]
Excellent article, I am curious how you handled owner rights
[…] Per Alex King, I have decided to use Subversion to track changes to my websites (echeng.com and wetpixel.com) over time. I used the SVN 1-Click setup to install an SVN repository and client on my Windows server, and just installed TortoiseSVN on my client machines. […]
[…] wasn’t the only change I made though, I finally did for alexking.org what I’d done for kingdesign.net a while ago, put the entire site in SVN. This makes it easy for me to test local changes and push […]
Actually, you can’t include a section in a .htaccess file; they’re only allowed in httpd.conf.
[…] SVN as a Web Site Maintenence Tool | alexking.org […]
[…] could configure your web servers config to deny access to any directory with “.svn” in […]
Adding that code to your .htaccess file will make your site break with a 500 error.
This code worked for me:
RewriteRule ^(.*/)?\.svn/ – [F,L]
ErrorDocument 403 “Access Forbidden”
And i found it here:
Well, Thanks for the informative blog. I had a question: I am a newbie to the world of development. I have developed few Java projects, some HTML/PHP code (mainly reading the tutorials) and now I feel ready to start working on a little complex website project. It will have a backend database too
My question is: how to use svn (say, torotoiseSVN) for personal project? I installed torotiseSVN, right clicked on a directory and made it my repository directory. But I still don’t get what I need to do, to use the power of svn.
Do I just write code file in eclipse or text editor, and save it in that directory?
What are the steps I need to do, and in which order, and how often?
Answer to this question might be helpful to not only me, but to newbie-developers who have never used SVN or source-control, but want to use it.
I will be using my laptop as my sole development machine, and I’d have svn repository on my laptop too – not a remote server. I’d like to upload updates to site to a webserver every day. To start with, I am going to be the only developer. But a friend might join me in future.
Good article, I found you thru the Dreamhost link. We’ve embraced subversion as well, and it’s had a difficult learning curve but now I’m thrilled we use it.
Successful web design is as much about process as design sometimes, it seems.
[…] previously familiar for his collection of WordPress themes) posted a very interesting idea about using SVN as a web site maintenance tool. Aaron and Jeff introduced me to SVN earlier this year and we use it to manage version control on […]