Composr Supplementary: Cloning your site

Written by temp1024
Have you ever wanted to know exactly what impact a specific upgrade, patch, addon, or change will have on your live site but were too afraid to try?

With the following instructions you can now find out exactly by creating a clone of your site and applying the changes to the clone.

This tutorial assumes your hosting control panel is cPanel. Other hosting control panels typically have similar features.


While the steps may seem a bit long-winded and fiddly, they should be straight forward enough. Please read the instruction completely first as you will need place your specific details in place of the following place holders:

   MAIN_DB_USERNAME
   MAIN_DB_NAME
   MAIN_DB_PASSWORD
   MAIN_SITE_DIR      ←The directory where you installed your main site

   CLONE_DB_USERNAME
   CLONE_DB_NAME
   CLONE_DB_PASSWORD
   CLONE_SITE_DIR      ←The directory where you installed your clone site
   CLONE_SITE_DIR_OLD

STEP 1: Install a fresh copy of Composr. This will be your clone site. If you already have another Composr site installed that you want to re-use and make your clone site then ignore this step.

STEP 2: Use the Composr upgrader tool (http://yourbaseurl/upgrader.php) to flush the caches of your master site. There is no need to close the site.

What the shell?

When I say "ssh window", I'm referring to the use of a Secure Shell console (terminal) application. Its the 'standard' secure tool/method of remote communication with a server.

Its a command-line tool (like Commandr). The advantage of using ssh over phpMyAdmin is that you can script/automate steps to do things simpler/faster/consistently.

Note that some hosts have SSH access disabled by default, and depending on your host, you would activate it either through your hosts self-service tools or by sending a them a support ticket.

If you don't like to use the shell (ssh) or do not have access, then steps 3-5 can be performed using a normal phpMyAdmin workflows. However, on some servers phpMyAdmin may time-out when exporting/importing databases, so the advanced steps have been included here.

STEP 3: Backup the database of your main site by executing the following command in a shell (ssh) window, taking care to first replace the place holders with your specific details:

Code (Bash)

mysqldump -uMAIN_DB_USERNAME -pMAIN_DB_PASSWORD MAIN_DB_NAME > main_db_backup.sql

STEP 4: Prepare the clone site's database to accept main site's database using the following ssh command (change place holders as required):

Code (Bash)

mysql -uCLONE_DB_USERNAME -pCLONE_DB_PASSWORD -BNe "show tables" CLONE_DB_NAME | tr '\n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " $1 ";SET FOREIGN_KEY_CHECKS = 1;"}' | mysql -uCLONE_DB_USERNAME -pCLONE_DB_PASSWORD CLONE_DB_NAME

STEP 5: Replace the clone site's database with that of the main site using the following ssh command (change place holders as required):

Code (Bash)

mysql -uCLONE_DB_USERNAME -pCLONE_DB_PASSWORD CLONE_DB_NAME < main_db_backup.sql

At this point you can delete main_db_backup.sql if you wish (by executing the rm main_db_backup.sql command in the ssh window). I sometimes don't if I'm going to be playing around with the tables of my clone site directly. So if I stuff something up I can just do steps 4 and 5 and I'm good to go.

STEP 6: Now, to clone the rest of the site. In cPanel do the following:

   a) rename CLONE_SITE_DIR directory to CLONE_SITE_DIR_OLD. The main reason for this is to protect the .htaccess and _config.php. If you are short on space then you can delete all files except those two.
Note: The first time you set up a clone site you might actually need to copy .htaccess from MAIN_SITE_DIR to CLONE_SITE_DIR_OLD and check if there are any site specific paths that need changing.

In my case there are two entries that have site specific paths The first is the ErrorDocument line, which ensures that 404 pages are displayed properly, and the second is a AuthUserFile line to ensure password protected directories work (I password protected my main site while it was in development).

Also, if your main site is based on recommended.htaccess then .htaccess should be copied otherwise you will most likely get Not Found errors when trying to access the cloned site.

   b) navigate to MAIN_SITE_DIR folder and select all files and folders in that folder.

   c) select copy function and change destination path from "/public_html/mydomain.com/MAIN_SITE_DIR" to "/public_html/mydomain.com/CLONE_SITE_DIR"

   d) copy the following files from "CLONE_SITE_DIR_OLD" to "CLONE_SITE_DIR" to ensure that the cloned site will work correctly:
      .htaccess
      _config.php

   e) delete CLONE_SITE_DIR_OLD directory

Congratulations!!!, you should now have a working clone of your main site!

A few things to note about the cloned site:
  • It's live, so anyone who has access to your main site has access to your clone site. If you don't want them to see the clone and the things under development you can either close the clone site (so only admins will be able to log in) or password protect the CLONE_SITE_DIR directory using cPanel's Password Protect Directories feature.
  • Although the bulk of the clone site uses dynamically generated URLs which will automatically adjust to the new location and URLs, any URLs you have hard coded or that appear in content will still point to the main site. The classic examples of this are the URLs in spacer posts. This has never been an issue for me.
  • Because the clone looks identical to the main site you might want to consider making some small but obvious change to the look of the clone so that it is easily distinguishable from your main site.
  • User notifications will still be active, so if you reply to a members post (say for example you are testing that post reply still works), and they have e-mail notifications turned on, they will receive the e-mail notification. You can disable e-mails in the configuration.

See also


Feedback

Please rate this tutorial:

Have a suggestion? Report an issue on the tracker.

Back to Top