Say you work on a desktop and a laptop computer, and you synchronize your laptop. Edit some files, save, and upload. Everything is fine. Now you get home or back in the office, sit down at the desktop, and forget to synchronize. You edit the files some more, upload, and save. Uh-oh, now you lost the changes you made on your laptop. You’ll have to get a copy off the laptop, and find all the changes you made. Ever done this? Version Control makes this scenario so much easier to resolve.
Update (2010-09-29): I’ve recently moved onto using mercurial for any new projects. Please let me know if you have any issues with the newer SVN server installers. I haven’t had a chance to update mine to the latest version. However, this tutorial should still work.
I’ve been putting off for quite some time setting up version control for the various websites I work on. I was finding myself sometimes editing a file, saving my changes, and getting uploaded to the site to find I had made an error or broke another feature. I’ve been using Dreamweaver to do my php coding and css editing, and enjoyed the easy benefit of using the synchronize feature. Dreamweaver makes it easy to get the lastest edits off the server, and have a local copy to work on. Dreamweaver will also save automatically back via FTP. However, it makes for a better WYSIWYG editor than a development environment, and does not offer any backup option.
I tried out a few PHP IDE’s like Netbeans. Wow, coding became alot simpler with the advantages of code completion and hints. Unfortunately, I didn’t seem to find an IDE that uses the synchronization feature, but all support SVN version control. I decided to take the plunge and setup my computers to harness the advantages of version control.
I’ve been using WAMP on several computers, and makes it just as easy to setup as it was in Ubuntu. WAMP is a pre-configured Apache, MySQL, PHP, phpMyAdmin, and SQLiteManager stack for Windows. You can setup a webserver in under 5 mins on your windows box. I have set this up on both Windows Vista x64 and Windows XP SP3. I followed several guides online, and each seemed to be missing a piece here or there. Also, beware of the SVN 1 click installer. The download contains a version of Subversion that’s not compatible with Apache 2.2.11 included with WAMP. I learned this the hard way.
Summary of Folder Layout
c:\clients\project1 -> Working Copy c:\svn -> Subversion Installation c:\svnrepos -> Repository Parent Location c:\svnrepos\project1 -> Sample Repository c:\wamp ->WAMP Installation c:\wamp\www\project1 -> Live Copy c:\Program Files\TortoiseSVN ->TortoiseSVN Installation |
You will need 3 things to get a WAMP + Subversion up and running.
- Wamp v2.0i
- Subversion
- TortoiseSVN v1.6.6
First, you need to install each of the packages. During the install of Subversion, select “Bind to Apache 2.2.x”. I chose to install subversion to:
c:\svn |
Try to prevent using spaces in your file paths to eliminate any problems in Apache. This will provide the right files to be installed that will work with the version of Apache that’s installed by WAMP. Now, that you have the packages installed, it’s time to marry WAMP with SVN. You will need to copy files between folders.
Copy mod_authz_svn.so and mod_dav_svn.so from
c:\svn\bin to C:\wamp\bin\apache\Apache2.2.11\modules |
Copy intl3_svn.dll and libdb44.dll
c:\svn\bin to C:\wamp\bin\apache\Apache2.2.11\bin |
Now click on the white half circle tray icon for WAMP->Apache->httpd.conf. We need to add these modules into Apache’s configuration file. Find the lines:
#LoadModule dav_module modules/mod_dav.so #LoadModule dav_fs_module modules/mod_dav_fs.so |
Change to:
LoadModule dav_module modules/mod_dav.so LoadModule dav_fs_module modules/mod_dav_fs.so LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so |
Save the file. Click on the WAMP tray icon again, and then click Restart All Services. Wait for the icon to turn all white again. When it does you are ready to proceed with setting up your first repository. If you have trouble, try exiting WAMP, and then start the application again.
Now you need to create a repository folder. I chose:
c:\svnrepos |
Since I will be hosting multiple projects go ahead and create another subfolder:
c:\svnrepos\project1 |
Now let’s create the repository by right clicking on the c:\svnrepos\project1 folder->TortoiseSVN->Create Repository Here. You will get a confirmation that folder was created successfully.
Update 2010-02-01:
I’ve noticed the latest build of TortoiseSVN is not creating compatible version for Apache, but will the command line version will work.
Open command line, and type:
cd c:\svnrepos\ svnadmin create c:\svnrepos\project1 |
Time to setup Apache to allow browsing of the repository. Click on the WAMP icon->Apache->httpd.conf. Scroll to the bottom of the file and above:
Include "c:/wamp/alias/*" |
Add:
<Location /svn> DAV svn SVNParentPath C:/svnrepos </Location> |
Save the file. Leave it open, and click on WAMP tray icon->Restart All Services. Wait for icon to turn all white again. Now you should be able to navigate to http://localhost/svn/project1. If successful, you should see a blank directory listing for project1 – Revision 0.
If you don’t require any authentication, you are done. Go have some fun and enjoy your free SVN repository. In Windows Explorer navigate again to c:\svnrepos\project1, right click on folder->TortoiseSVN->Repo-browser. In the right-hand pane right click again->Create directory. Then type in trunk. Repeat to create folders branches and tags. Now start importing your files into the trunk folder. Do this by right-click in right pane->Add File(Folder). Choose a file/folder, add a comment and click okay. You now have started your repository. You can refresh the browser page and check out the changes.
Ready to add user authentication? It’s easy to setup a basic user/password method. First we need to create a password file for Apache to protect the browsing of the repository. Create the password file by using the command line:
cd C:\wamp\bin\apache\Apache2.2.11\bin htpasswd -c svnpasswd username |
Open httpd.conf file again. You need to add a few commands to the
SVNParentPath C:/svnrepos |
Add:
AuthType Basic AuthName "Subversion Repository" AuthUserFile bin/svnpasswd Require valid-user |
Click on WAMP tray icon->Restart All Services. Refresh your browser page and you should be asked for your login credentials. Congrats! Remember this authentication method only protects browsing. It does not control who can read/write/edit/commit/delete file from the repository.
Putting It All Together
We’ve got WAMP/SVN up and running, but how do you use this? Here’s what I am doing right now. Get all the files imported into your repository /trunk folder using TortoiseSVN. I created folder for my working copies that I will be developing and testing. I used:
c:\clients |
Navigate to this folder create a new folder (ie. project1). Right click on folder->SVN Checkout . Fill out as shown:
Click OK, and all the files from the repository will be copied/downloaded to the folder. In order to be able to debug/test your working copy, create an alias that points to that folder. I use an alias because I use my WAMP webroot for serving real pages. Right click WAMP tray icon->Apache->Alias directories->Add alias. A command prompt will open, type in alias and the path to the folder using forward slashes.
svnproject1 [Press Enter] c:/clients/project1 |
Point your browser to http://localhost/svn/project1, and you should see your test site. You have a separate method to test your working copy. Make some changes/edits of files. Commit your changes to the repository by right click on the folder:
c:\clients\project1 |
Choose SVN Commit, enter a comment, and click OK. Once you have a working copy you would like to move to live, navigate to:
c:\wamp\www |
Right click in Windows Explorer->SVN Checkout and fill out as shown:
Click OK, and the latest revision will be copied to the folder. Browse http://localhost/project1. You are running a live copy. Whenever you’ve ready to roll out an update, just right click on the folder->SVN Update. All changes will be synchronized.
I am running this setup at work for one of our small internal web applications. I have the repository on my computer. I’ve created a working copy. I work on adding some new reports, or improving the UI with some jQuery. Test it locally, and fix any bugs. Open a ssh session to the server an issue “svn update” in the webroot, and the applications are updated without going down.