How to copy a PHP website

Written by tiesha whatley
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to copy a PHP website
Copy the entire PHP site to create a mirror of the site or to transfer it to another location. (usb storage device image by Francois du Plessis from Fotolia.com)

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.

Skill level:
Easy

Other People Are Reading

Instructions

  1. 1

    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.

  2. 2

    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.

  3. 3

    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 != '.' ) &amp;&amp; ) $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.

Tips and warnings

  • This script only copies the PHP files and not the database behind the site. You will need to export all of the data from your database and input it into a new database on the new server for it to work. Go to the MyPHPAdmin application on your CPanel (the web hosting management tool that came with your hosting account), select the database you want to copy and click on "Export." The database will be exported as a CSV file.

Don't Miss

References

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.