Checkout SVN with PHP

Subversion (SVN) is a version control system that allows multiple developers to work on code simultaneously without coming into conflict (further information on SVN can be found on Wikipedia). Here at Brightlemon we find ourselves working on ever more complex sites and SVN has become a very useful tool that, if required, allows all staff to work on a site at any one time. We use a windows SVN client called Tortoise SVN so that we can work remotely on code and then commit to a central SVN repository.

When it comes to updating a site by checking out the code from a repository we usually run commands via an SSH shell connection, however we have found recently that when we are working with external companies (and even for new staff) then it useful to have an additional method for checking out the code that does not require SSH access to a server. We have achieved this by creating a PHP script that executes SVN commands in the following way. In order to use a PHP script that can run SVN commands you must ensure that your apache user (normally called 'www-data') has sufficient permissions to:

  1. create and edit folders
  2. run SVN commands

Your PHP script should then contain the following:

You should replace the following with your own values:

  1. SVN-USERNAME - the username you use to connect to your SVN repository
  2. SVN-PASSWORD - the corresponding password you use to connect to your SVN repository
  3. SVN-REPOSITORY-LOCATION - the URL location of the respository you are checking out
  4. DESTINATION-FOLDER - the location on the server where the repository should be checked out to (if omitted the basename of the URL will be used as the destination).

You should save this as a file called 'checkout.php' on your webserver. Then using this script anyone (with access to this page) can checkout your SVN repository without requiring any knowledge of shell or SVN commands by opening the following URL in a browser http://your-domain.com/checkout.php.