My last post about setting up a Virtual Machine to use as your local webserver was quite the success (hits increased from about 30 to nearly 1000 within 2 days…and dropped back to somewhere slightly above the old value by now) and I promised I would write some more tutorials on how to install some useful libs, so here we go and start with SVN in combination with TortoiseSVN a SVN client for Windows.
For those that haven’t heard of SVN before, here’s a short summary from Wikipedia:
Apache Subversion (often abbreviated SVN, after the command name svn) is a software versioning and a revision control system founded and sponsored in 2000 by CollabNet Inc. Developers use Subversion to maintain current and historical versions of files such as source code, web pages, and documentation.
And here are some terms you’ll run into.
- Repository: SVN creates a repository for each project and it’s basically the place where all the files and their history is stored. It’s located on the server that runs SVN, in your case propably the VM from my last tutorial.
- Checkout: It’s your local copy of the repository where you make your changes to the files. It’s usually located on your local machine in your webserver root where you work and edit files. In your case that’s propably not the case and it would be in the /var/www on your VM because that’s where you work via shared folders.
- Commit: It’s a command that sends all the changes you made to the files in your checkout folder to the repository. Each commit creates a new revision with it’s own number that let’s you revert your files to an older version that you commited before.
- Update: Compares your local copy to the repository and updates your local files to mirror any changes commited by other users since your last checkout/update.
Installing SVN is actually pretty easy, like most of the libs. Configuration is where it might get tricky, but we’ll come to that in a bit.
apt-get install subversion libapache2-svn
That’s it, SVN is installed. Now we can start with the configuration. First we gotta think of a place where we want to locate our repositories. I located mine in the home folder but you can put it pretty much everywhere you want:
Now we’ve created a folder called “svn” in /home and can continue by creating a passwd file we can use for all upcoming projects:
htpasswd -c /etc/subversion/passwd <user name>
This will prompt you to enter a password for the user. You can choose whatever user name and password you want. These credentials will be used to access your repositories. I chose user name “root” with my root password out of habit, but it’s entirely up to you. Now that we are all set we can setup our first project.
Setting up a project
These steps need to be taken whenever you want to start a new project with it’s own repository. In the following please replace <project name> with the name of your project, it shouldn’t contain any characters that don’t work well with URLs, e.g. umlauts or space, and keep it lower case just to be sure. First we create a folder for the new project in our svn folder and then we create the repository:
mkdir <project name>
svnadmin create /home/svn/<project name>
Next thing we need to do is configure Apache to allow TortoiseSVN to connect to our repository:
Now that you’ve opened the Apache config file, please scroll to the bottom and insert this and save the changes:
<Location /svn/<project name>>
SVNPath /home/svn/<project name>
AuthName “<project name>”
<LimitExcept GET PROPFIND OPTIONS REPORT>
Now run this command to make sure the repository is owned by the HTTP user:
chown -R www-data:www-data /home/svn/<project name>
This will tell Apache that our repository can be found under http://ip-address-of-my-vm/svn/<project name> and allows us to use a client like TortoiseSVN to connect to our repository.
Now you have to restart Apache and after that your repository should be ready to go:
First we need to download and install TortoiseSVN from their website. Choose the version matching your system (32 or 64bit) and install it using the pre-selected options after the download is done. I use the 64bit version but there shouldn’t be any differences to the 32bit version. If you are asked to reboot, then please do so and afterwards go to the shared folder from your VM where you usually work in.
Right click and select “SVN Checkout”. It opens a new window where you are asked to enter the URL of the repository and the Checkout directory. For the first one you enter
and the second one defaults to the <project name> but you can choose whatever folder you want as long as it’s empty (it doesn’t have to exist yet, TortoiseSVN will create it if needed). Leave the other options as they are and click “OK”. You should see a new window that says “Completed At revision: 0” or something like that.
Now you can navigate to the new folder and start working on your project. If you’ve done some changes, e.g. created a new file or whatever and want to commit them to the repository, then simply right-click the project folder and select “SVN Commit”. You’ll see a text input at the top and a list of all new/deleted/changed files below that. In the text are you are supposed to enter a “message” or rather a comment which describes what has changed and below you should select all files that are related to these changes/de-select all files that are not related. After clicking “OK” your changes will be tranferred to the repository and new revision will be created.
Small tip: If you want to enhance existing projects of yours with some SVN powered version control, then you can simply create a new project like I describe above, copy your files from their old project folder to the new one and commit your changes.
If you are not the only one working on the repository, e.g. because you are using the VM in the local network of your company, you’ll need to run “SVN Update” now and then (each time you start working propably) to make sure you have the latest versions of the files and don’t work on old copies that have already been changed by someone else.
SVN offers some more options but I guess you can figure them out yourself by playing around with TortoiseSVN, at least that’s how got to know it ;) Feel free to leave a comment if you want me to elaborate on some of the options.
That’s it. You’ve successfully setup SVN+TortoiseSVN and can start working in a safer environment where you can keep track of all your changes.
I hope you like this tutorial as much as you liked my last one and I’m looking forward to your comments and critique.
will be good if there are some picture :)