20

Recently, one of my clients asked me to mirror his web server. The only problem with this request was that I host his web site on my WHM reseller account, and his budget would only cover another shared hosting package. Mirroring one shared hosting server via another shared hosting server seemed possible; however, I knew that the budget constraints meant I would be piecing together my own solution…

Now a couple of months after his request, I am happy to report that I have successfully setup a mirror of my client’s CPanel/WHM server. My technique combines the right combination of service providers, public key ssh authentication, rsync, mysqldump, and DNS Failover switching.

The Scenario
In this tutorial I am going to show you how to mirror a web server using two shared hosting accounts. Our mirror web server will automatically backup all scripts, files, and databases on the production web server. In addition, this tutorial will also describe how to setup DNS fail over switching that will monitor the status of the production server and automatically switch the DNS to point to the mirror server should the production server fail.

As this technique involves five distinct steps, I have divided this post into the following sections:

20 Responses to “Mirror a Dynamic Website on a CPanel/WHM Server”

  1. Naseer Khan says:

    Hi,
    Please could you tell me if you have ever done mirroring for the plesk web servers.
    Thanking you.
    Regards,
    Naseer.

  2. Davi Souza says:

    This is for ressellers, how to backup entire dedicated server with cpanel and whm???

    the sql sync isn´t good enough, imagine if i need to create all database of accounts??? is it possible to copy all information between the servers???

    thanks – but at all is very good tutorial….

  3. AndyW says:

    Michael, I find your article very informative and helpfull. Thank you very much for same.

    Was wondering since you posted it on 2007, how has the setup performed since then? Are you still using it or have you moved to a more advanced setup.

    Just want to get your production experience of it, before I implement it on a bunch of websites.

    Thanks in advance.

  4. Peter says:

    If the server still asks for password then you need to check the following permission in your server.

    * Change the permissions of .ssh to 700
    * Change the permissions of .ssh/authorized_keys2 to 640

    It took me 2 days to figure this out.

  5. Sam says:

    Hi,

    The tutorials sections don’t load anymore. Do you have a downloadable pdf?

  6. Sam says:

    Hello 1st thank you very much for this great tutorial, im trying to copy the key from server to another, but the production server isnt able to recodgnize the command, its centOS
    any other other command to copy the key?

    thank you

  7. Shad says:

    I’m very interested to see if anyone has found a reliable solution to mirror two complete servers with whm – not just reseller accounts. We have about 200 clients on a whm server and we only have backups – no failover. I’d like a solution with complete failover redundancy in case some natural disaster or something happens in one location. Nowadays with all the catastrophes happening around the world – I want to make sure if a tsunami or earthquake hits – we’re not going to be down forever. Several clients’ have dedicated IP’s as well for the SSL certs and shopping carts.

  8. Evan M says:

    Hey Michael,

    Came across this a few months ago and set it up – it’s working brilliantly. We have a few different VPS’s running WHM/cPanel strategically selected in DC’s around the world and have had five 9′s of uptime since we’ve implemented your solution.

    Thanks for the help; it’s greatly appreciated!

  9. Shashank says:

    This worked for me in step 2 instead of the command shown.

    cat ~/.ssh/id_dsa.pub | ssh user@serverIP ‘cat >> ~/.ssh/authorized_keys’

    Awesome tutorial btw

  10. Shashank says:

    The following command worked for me in step 3:

    rsync –delete-after -avzn -e “ssh -p 11141″ shashank@59.99.254.17:~/public_html ~/

    Thanks!
    Shashank

  11. Filipe says:

    Interesting, but what do you recommend as for the cron? 5 by 5 minutes?

    What about syncing back the database when master comes alive?

    • Michael says:

      The site I use this technique on doesn’t update frequently enough to need anything more than a cron that runs once every twenty-four hours. In addition, the site hasn’t been down long enough for anyone to try making changes on the mirror that need to get synced back. My client is aware of this, and hasn’t invested to solve this problem as it doesn’t affect us much in this case. You pose good questions though which shouldn’t be too hard to solve.

  12. Imb says:

    Thanks for this great tutorial.
    I see that this is for cpanel to cpanel mirror.

    Do you know a solution for WHM to WHM mirror?
    I need to mirror at least web files and database once a day of each cpanel account in WHM. (The emails do not need to be mirrored).

  13. rajan anuraj says:

    while running that mysqldump command which you have stated is throwing error as it is not able to connect the production server. Seems like it is running in localhost. Could you please us know if you have enabled remotehost for the production server and if yes, how… \

    thank you
    regards,
    anuraj

    • Michael says:

      In cPanel, you can add remote database access hosts via the “Remove MySQL” section under “Databases”. Add the IP of your mirror on your production server, and add the IP of your production server on your mirror.

Trackbacks/Pingbacks

  1. How To Mirror a Website? « Sync Blog - August 30, 2011

    [...] Tutorial credits goes to Michael on Wenderhost 0 [...]

Leave a Reply