How to copy a site to another directory

Last updated on
12 February 2018

System: Apache + PHP + MySQL + Linux

I had my site at, say, and wanted to set up as a duplicate site to test some ideas. This meant duplicating the database and code to a separate database and code tree. That way I could modify without harming

In my case, I'm on a virtual-private-server (same thing as a dedicated server) and have full control over the system. If you're on a shared hosting account the steps will be different. Unfortunately the details of how shared hosting accounts are setup vary so widely, I'm not going to try and generalize the instructions for that.

  1. In the DNS, create the subdomain. Remember it can take a little while for the DNS entries to propagate properly.
  2. Duplicate the database tables ... I'm on Mac OS X and used the navicat program to do so, but you should be able to use mysqldump or other similar programs. That is, create a new database and copy the tables and data from the database to the one for
  3. Make a directory for the docroot of, and copy the files as so:
    (cd; tar cf - .) | (cd; tar xvf -)

    If you only have FTP access this is a little harder. First FTP the files to your local computer, then FTP those files into the new docroot directory. You can also edit the files on your local computer, and then re-FTP them whenever you change something.

  4. Config apache's httpd.conf for a second VirtualHost with in it. Make sure the VirtualHost entry for precedes the one for Make sure the docroot for is a different directory.
  5. Edit sites/default/settings.php and change base_url and the database URL.
    $base_url = '';
    $db_url = 'mysql://username:password@localhost/new-database';
  6. It's also helpful to override the site name so that the heading on the site glaringly reminds you that you're on the BETA site:
    $conf = array('site_name' => 'BETA this sites name');