How to Copy a PHP Website

You've spent a great deal of time and money to set up and configure your PHP website just right. Now, for some reason, you need to copy it to another web server or to a different folder on your current web server. You have several different options for how to do this. Use a PHP script to copy the file to another location. You just need to create the script, load it to your web server and run it. All of the files on your site will be copied to the new destination.

Video of the Day

Copy the entire PHP site to create a mirror of the site or to transfer it to another location.


Open a text editing (Notepad) or web authoring application on your computer. Click on "File" and then "New" to create a new file. There also may be a "New" icon on the toolbar.


Type in the following PHP code to copy files from one location to another:

"bool copy (string $source, string $dest [, resource $context])"

Leave out the quotation marks when typing the code. Change "source" to the file location of the PHP file that you want to move. Change "dest" to the destination location to where you are moving the PHP file to.


Type in the whole script to copy all of the files on your web server to another location. To save some time when you have a lot of files, use the following script to copy the entire public_html directory to another location:

"<?php function copy_all($source,$dest) { $dir = opendir($source); @mkdir($dest); while (false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ) $file != '..' )){ if (is_dir($source . '/' .$file) ) { copy_all($source. '/' . $file,$dest.'/'.$file); } else { copy($source.'/'.$file,$dest.'/'.$file); } } } closedir($dir); } ?>"

Omit the quotation marks at the beginning and end of the code. Save the file as a PHP file and upload it into your public_html folder on your web server. Run the script by typing in the file location in the address bar of a web server. Input the destination you want the files copied to and then allow the script to do its job.

Show Comments