how to update a live site from a staging site when using svn

We are working with the following situation:

  • we have an svn repository with a website
  • we have checkout the repository on a webserver in  a sub-directory (e.g.
  • what we want to achieve is to get the same files as we have in the test-directory in the root directory for the website (i.e. move all the files one folder up the tree)
  • We are working with a Silverstripe Website

Now - there are many ways to do this. What we want to consider are:

  • what is fast?
  • what is easy to maintain
  • what is fail-proof

The nice thing for this setup (having the test website in the sub directory and the live website in the root directory) is that theoretically, you can run a test website and a live website on your same server.  You can even do this running independent databases.  So - how do we go about this?

The first thing to know is that there are two files within the Silverstripe Setup that need changing: .htacess and _ss_environment.php.  All the other files can stay the same.  In the .htaccess, you will need to change

RewriteBase /test-site


RewriteBase /

If you really want to crank it up then you can also add password protection to the dev site using something like this

For the _ss_environment.php file, you can set all your other site depended settings.  Here is an example:

define('SS_ENVIRONMENT_TYPE', 'dev'); //set to dev or live - this is very important to get right.

/* Database connection */
define('SS_DATABASE_SERVER', 'localhost'); //
define('SS_DATABASE_USERNAME', 'alpha'); //
define('SS_DATABASE_PASSWORD', 'romeo'); //
define('SS_DATABASE_PREFIX', 'staging_');// this can be useful if oyu have a different database name for staging and live

/* Configure a default username and password to access the CMS on all sites in this environment. */
define('SS_DEFAULT_ADMIN_USERNAME', 'alpha');
define('SS_DEFAULT_ADMIN_PASSWORD', 'remeo');

Now here are the options for updating the live site from the test site.

using ftp - copy the files from one folder to the other

Takes forever, is prone to errors and is difficult to maintain.  However, it is easy to understand and you do not need ssh access.

using ssh - doing a straight copy

This is a bit dangerous, but also very fast.  Open ssh, browse to the live directory and type in:

cp test-dir . -r

We have not tried this and we definitely would read the manual first before doing this.

using svn - doing a fresh checkout of the test repository

You will need ssh access for this.  For this, the test site needs to have the test-site directory as its root directory. The test and live site will always be exactly the same.To do this, open ssh, go to the live directory and typ in the following:

svn chekout

Where is the location of your repository. After that, you will need to manually add the .htaccess and _ss_environment.php files.

using svn - merging the test directory into the live site

This is really the proper way. You will need to setup a second repository for the live site.  First of all, you checkout the live repository (which can be empty).  Lets call it and the test site is Now login with ssh, and go to the live direcotory - root of your website and type:

svn checkout
svn merge
svn update

Note that you need to type in three commands in total.  After that, create the .htaccess and _ss_environment.php files and you are done.

just  in case you need to remove the svn directories

use the following code in your in your ssh console (all .svn entries will be removed in your current folder and below - aka child folders)

rm -rf `find . -type d -name .svn`