Recenty, I was engaged in a number website migrations between servers. One from a shared hosting to a dedicated cloud server instance on Google Cloud running Debian OS. It was pretty easy, as all that is required is to zip the entire website content using the compress tool provided in the Web host’s control panel, and download to the new server using
command. This is extremely useful, if you have a slow connection, large amount of data and you want to maintain your directory structure. In my case, I was having tens of thousands of files at different directory levels, all totaling 2.5GB.
Shared Hosting running cPanel
My brother’s website (Mustee’s Clothing) was recently redesigned using wordpress and hosted on a separate domain during design. One Night while working on migrating it to his original domain, the first idea was to download the direcotry containing the design to my PC and later upload to his domain, both using FTP. Then I thought, that will be a serious waste of time and decided to look for easier ways. Then I thought of exploring PHP curl, since I have used it in consuming APIs before. After few minutes of research, I was able to come up with:
$url = 'http://olddomain.com/site_content.zip';
$fp = fopen (dirname(__FILE__) . '/site_content.zip', 'w+');
$ch = curl_init($url);
CURLOPT_URL => $url,
CURLOPT_BINARYTRANSFER => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_FILE => $fp,
CURLOPT_TIMEOUT => 50,
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'
$results = curl_exec($ch);
if(curl_exec($ch) === false)
echo 'Curl error: ' . curl_error($ch);
The $url variable contains the link to the compressed site on the old domain, and using curl, the compressed file is downloaded to the same directory the script is contained in. You can then extract the site contents and move it to which ever location you desire, all using the file manager functionality provided by your cPanel installation. The script downloaded the 25MB website content in 2 seconds.
You can explore PHP’s curl further here.