Difference between revisions of "Making a Local Copy"

From Zen Cart(tm) Wiki
Jump to: navigation, search
m
(added back the FTP recommendations because it's a popular inquiry)
 
(16 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
{{Template:menuBarInstallation}}
 
{{Template:menuBarInstallation}}
== Making a Local Copy of Your Web Site ==
 
  
If your Web site is hosted on a remote server, it is common practice to have a parallel copy of the site on a local computer for development and testing.
+
If your web site is hosted on a remote server, it is common practice to have a parallel copy of the site on a local computer for development and testing.
  
This is not difficult, but requires certain preparation before the copy can be installed. Faster access than dial-up will be well worth the cost if available.
+
==Configuring local PC as a server==
 +
A prerequisite is to configure the local PC as a PHP/Apache/MySQL server.  Detailed information for various OS's can be found [[Installation:LocalServer|here]].
  
=== Preparation ===
+
== Copying Files and Database from the Remote Server ==
  
First, you will need server software and accessories (Apache or other server, MySQL, PHP etc.) These can be installed individually, but if you have the skill to do that you probably don't need this guide. Numerous open source packages are available. To make local work most relevant to the remote site, it makes sense to choose software as similar as practical. You will probably also need a utility to extract zip or gzip files, again readily available in open source.  
+
If your remote site uses Cpanel for access, there is a ''Backup'' page where you can download a backup of your entire server space in a gzip file with one click; however, you have no control of what is included. To download your database, phpMyAdmin is accessible through a tiny link at the bottom of the MySQL page. It is very flexible; though unless you know what you are doing, be sure to follow the steps below exactly. You don't need to add anything to the __DB__; the file will be saved as your_db_name.sql.gz. If you want to add a distinguishing tag to this copy, add it after the __DB__, e.g. __DB__07_23 to get your_db_name07_23.sql.gz.
Note: Zen Cart through v1.2.7 is not compatible with MySQL 5.x - see [[Troubleshooting|Troubleshooting-Errors-1054]]. This is addressed in v1.3.0.  
 
  
Install the server package per the supplier's instructions (it will probably be quite simple.) It is good to locate it near the root (C:\ or C:\Program Files). If you mess up at any point you can uninstall or delete everything and start over. You will then want to create a database using phpMyadmin, probably accessible through the server admin. Don't worry about where it goes; MySQL takes care of that. Don't move the db or it will be lost. You will later import the downloaded db information from a .sql file or similar.
+
===Via command line===
 +
If you're comfortable on the command line, backing up the database is trivial. After ssh'ing into your host you can back up whatever you like using mysqldump.  To backup your entire database you would run:
 +
  mysqldump --host <yoursqlhost> -u <your_store_sql_username> -p  <your dbname> > backup.sql
 +
This creates the sql statements needed to create the table and populate it in a new database server.   
 +
Now on your local copy, you need to import the database. To minimize the differences between your local and remote installations, it is reasonable to:
 +
In the mysql command line, create a database with same name as remote database:
 +
  mysql>CREATE DATABASE db_name
 +
Create same user, and grant permissions
 +
  mysql>GRANT ALL PRIVILEGES ON db_name TO 'username'@'hostname';
 +
Then from the bash shell, you just redirect the sql into mysql:
 +
  bash>mysql -u username -p database_name<backup.sql
 +
Note that you're going to have to have different hostnames.
  
You will install the site files in a subdirectory you create in (probably) \<server>\htdocs\ or the like (sometimes referred to as C:\internet\). Phpinfo will give Document Root, which is the part of the file path that will be replaced by <nowiki>http://localhost/</nowiki> when typing your local site address in the browser.
+
A detailed discussion of mysqldump can be found [http://www.devshed.com/c/a/MySQL/Backing-up-and-restoring-your-MySQL-Database/ here]. A more detailed discussion of the topic can be found [http://www.mydigitallife.info/2007/07/21/how-to-backup-and-restore-export-and-import-mysql-databases-tutorial/ here].
  
==== Open source server packages ====
+
=== TO BACKUP THE DATABASE ===
(Anyone with knowledge of other systems, please add that information.)
 
 
 
[http://www.apachefriends.org/en/xampp.html XAMPP]:  Easy to install and use, though it would help to have *some* idea of what to expect before starting. Minor glitches probably due to my initial inexperience and old computer. Support site primarily German but with an English section (all docs available in English).
 
 
 
[http://www.easyphp.org/ EasyPHP]:  Additionally, There is another Open Source Local Server package available,  it is EasyPHP and can be found here [http://www.easyphp.org/ EasyPHP], I only have experience with this distribution, but found it simple to install and use.
 
 
 
=== Copying Files and Database from the Remote Server ===
 
 
 
If your remote site uses cpanel for access, there is a Backup page where you can download a backup of your entire server space in a gzip file with one click; however, you have no control of what is included. To download your database, phpMyAdmin is accessible through a tiny link at the bottom of the MySQL page. It is very flexible, though the default settings will force the copy when imported to create another db named the same as the original. (It is possible to get around this if desired, e.g. making two copies locally, by editing the .sql file to remove the CREATE statement and change the SET and USE statements to your desired copy name.)
 
 
 
Thanks to DrByte for the following:
 
 
 
====TO BACKUP THE DATABASE====
 
  
 
These are the ideal settings to do a backup via phpMyAdmin:
 
These are the ideal settings to do a backup via phpMyAdmin:
  
NOTE: BEFORE clicking on "Export", you should select your database from the dropdown, so that its tables are displayed. THEN click on the "Export" tab.
+
Note: Before clicking on ''Export'', you should select your database from the dropdown, so that its tables are displayed. Then click on the ''Export'' tab.
  
 
* CHECKED: Structure
 
* CHECKED: Structure
Line 47: Line 44:
 
* Compression: "gzipped" (or whatever you prefer... gzip makes smaller files)
 
* Compression: "gzipped" (or whatever you prefer... gzip makes smaller files)
  
====TO RESTORE THE DATABASE====
+
 
 +
===TO RESTORE THE DATABASE===
 
* open phpMyAdmin
 
* open phpMyAdmin
* select the database you wish to restore INTO, from the dropdown menu
+
* select the database you wish to restore into, from the dropdown menu
* click on the "SQL" tab (in newer phpMyAdmin versions, you might have to click the "Import" tab instead, to get the "Browse" button mentioned next: )  
+
* click on the ''Import'' tab (in older phpMyAdmin versions, you might have to click the ''SQL'' tab instead, to get the ''Browse'' button mentioned next: )  
* click on the Browse button, and select the file you downloaded when making the backup
+
* click on the ''Browse'' button, and select the file you downloaded when making the backup
* click Go
+
* click ''Go''
 +
 
  
====DOING FILE BACKUPS====
+
===DOING FILE BACKUPS===
 
You will want to download an FTP client to transfer files. You can select exactly which parts of your server space to copy. Be aware of the progress of selecting - depending on program, connections and settings it is possible to time-out in the middle of a long selection process, and picking up where you left off risks missing or misaligning some files.
 
You will want to download an FTP client to transfer files. You can select exactly which parts of your server space to copy. Be aware of the progress of selecting - depending on program, connections and settings it is possible to time-out in the middle of a long selection process, and picking up where you left off risks missing or misaligning some files.
  
 
Some good FTP programs are: [http://filezilla.sf.net FileZilla] and [http://www.flashfxp.com FlashFXP]
 
Some good FTP programs are: [http://filezilla.sf.net FileZilla] and [http://www.flashfxp.com FlashFXP]
  
=== Installing your site copy ===
+
 
 +
== Installing your site copy ==
  
 
[Copied from FAQs - tweaked for this use]
 
[Copied from FAQs - tweaked for this use]
  
 
#On your local host, create a new MySQL database. Note the username, password, database name, and host name (usually localhost).
 
#On your local host, create a new MySQL database. Note the username, password, database name, and host name (usually localhost).
#On your local host do a fresh NEW install using the same version files that you built your other site on....<br />this will make sure that you get the proper settings in your configure.php files....<br />While installing, allow it to install the demo products, so that you can test and be sure that it's working nicely.(Optional)
+
#On your local host do a fresh new install using the same version files that you built your other site on - this will make sure that you get the proper settings in your ''configure.php'' files. While installing, allow it to install the demo products, so that you can test and be sure that it's working nicely.
 
#*Install.
 
#*Install.
 
#*Test it.
 
#*Test it.
#*Make backups of the local server's /includes/configure.php and /admin/includes/configure.php files by copying them to an easy-to-find place.
+
#*Make backups of the local server's ''/includes/configure.php'' and ''/admin/includes/configure.php'' files by copying them to an easy-to-find place.
#Download a COMPLETE backup of your DATABASE and STORE.
+
#Download a complete backup of your database and store.
 
#*Use either:
 
#*Use either:
 
#** the "Backup MySQL Database" contribution under Admin->Tools to do the backup of your database, or
 
#** the "Backup MySQL Database" contribution under Admin->Tools to do the backup of your database, or
#**use phpMyAdmin to export your entire database ... include the "DROP" tables command, and under Data, choose "Complete Inserts" and "Extended Inserts".<br />Save the SQL file to your PC for later and note how to get to it.
+
#**use phpMyAdmin to export your entire database ... include the ''DROP'' tables command, and under Data, choose ''Complete Inserts'' and ''Extended Inserts''. Save the SQL file to your PC for later and note how to get to it.
 
#*Download all your old site's files via FTP (or if you have the option, zip them up on the server and download the zip)
 
#*Download all your old site's files via FTP (or if you have the option, zip them up on the server and download the zip)
 
#Now we need to deal with the files. There are two approaches you could take:
 
#Now we need to deal with the files. There are two approaches you could take:
#*Upload your OLD files over the NEW files on the NEW server, WITH TWO EXCEPTIONS:<br />Don't overwrite the /includes/configure.php and /admin/includes/configure.php files on the NEW server.
+
#*Upload your old files over the new files on the new server, with two exceptions:<br />Don't overwrite the ''/includes/configure.php '' and ''/admin/includes/configure.php'' files on the new server.
 
#*(Alternate:)
 
#*(Alternate:)
#**Rename the directory holding the NEW cart you installed from /<newcart> to /<newcart_save>.
+
#**If you are not confident about keeping the configure files from being overwritten, copy them to a safe place before starting, and then continue with the process above.
#**Rename the directory holding your downloaded old site from/<dl_old> to /<newcart>. Make sure the files are all in the same relative places as the <_save> version. (The expanded directory trees should look the same.)
+
#**Replace the configure files if necessary after uploading is complete.
#**Rename the /includes/configure.php and /admin/includes/configure.php files from your old site to "configure_old.php".
+
#Go back to phpMyAdmin on your new server.
#**Copy the configure.php files from /<newcart_save> to the same places in /<newcart>. If you had previously changed anything in your configure files, you can carefully copy those changes from configure_old to configure.
+
#*Select your new database (that you installed the new Zen Cart&trade; into)
#Go back to phpMyAdmin on your NEW server.
+
#*''DROP'' all the tables. (Check them all and scroll down and on ''With Selected...'' select ''DROP''. Confirm Yes.
#*Select your NEW database (that you installed the NEW Zen Cart into)
+
#*Click on the ''SQL'' tab across the top and click ''Browse''.
#*DROP all the tables. (Check them all and scroll down and on "With Selected..." select DROP. Confirm Yes.
+
#*Select the SQL file you made in step 3a when you exported your old database, and click ''Go''.
#*Click on the SQL tab across the top and click Browse.
+
#Grab the "Fix_Cache_Key" utility to reset your Admin > Sessions > Session Directory key: [http://www.zen-cart.com/index.php?main_page=product_contrib_info&cPath=40_54&products_id=82 Fix Cache Key Utility]<br />Simply upload the file to your new Zen Cart&trade; folder and open ''fix_cache_key.php'' in your browser. It will give you status messages. Delete ''fix_cache_key.php'' when you're finished.
#*Select the SQL file you made in step 3a when you exported your old database, and click Go.
+
#You're done. Open your store and ''Admin'' areas to see it all ready to go.
#Grab the "Fix_Cache_Key" utility to reset your Admin->Sessions->Session Directory key: [http://www.zen-cart.com/index.php?main_page=product_contrib_info&cPath=40_54&products_id=82 Fix Cache Key Utility]<br />Simply upload the file to your NEW Zen Cart folder and open fix_cache_key.php in your browser. It will give you status messages. Delete fix_cache_key.php when you're finished.
+
[[Category:Installation]]
#You're done. Open your store and admin areas to see it all ready to go!
 

Latest revision as of 06:36, 7 May 2009


If your web site is hosted on a remote server, it is common practice to have a parallel copy of the site on a local computer for development and testing.

Configuring local PC as a server

A prerequisite is to configure the local PC as a PHP/Apache/MySQL server. Detailed information for various OS's can be found here.

Copying Files and Database from the Remote Server

If your remote site uses Cpanel for access, there is a Backup page where you can download a backup of your entire server space in a gzip file with one click; however, you have no control of what is included. To download your database, phpMyAdmin is accessible through a tiny link at the bottom of the MySQL page. It is very flexible; though unless you know what you are doing, be sure to follow the steps below exactly. You don't need to add anything to the __DB__; the file will be saved as your_db_name.sql.gz. If you want to add a distinguishing tag to this copy, add it after the __DB__, e.g. __DB__07_23 to get your_db_name07_23.sql.gz.

Via command line

If you're comfortable on the command line, backing up the database is trivial. After ssh'ing into your host you can back up whatever you like using mysqldump. To backup your entire database you would run:

 mysqldump --host <yoursqlhost> -u <your_store_sql_username> -p  <your dbname> > backup.sql

This creates the sql statements needed to create the table and populate it in a new database server. Now on your local copy, you need to import the database. To minimize the differences between your local and remote installations, it is reasonable to: In the mysql command line, create a database with same name as remote database:

  mysql>CREATE DATABASE db_name

Create same user, and grant permissions

  mysql>GRANT ALL PRIVILEGES ON db_name TO 'username'@'hostname';

Then from the bash shell, you just redirect the sql into mysql:

 bash>mysql -u username -p database_name<backup.sql

Note that you're going to have to have different hostnames.

A detailed discussion of mysqldump can be found here. A more detailed discussion of the topic can be found here.

TO BACKUP THE DATABASE

These are the ideal settings to do a backup via phpMyAdmin:

Note: Before clicking on Export, you should select your database from the dropdown, so that its tables are displayed. Then click on the Export tab.

  • CHECKED: Structure
  • CHECKED: Add DROP TABLE
  • CHECKED: Add AUTO_INCREMENT value
  • CHECKED: Enclose table and fieldnames with backquotes
  • CHECKED: Data
  • CHECKED: Complete Inserts
  • CHECKED: Extended Inserts
  • CHECKED: Use hexadecimal for binary fields
  • Export Type: INSERT
  • CHECKED: Save as File
  • Filename Template: __DB__
  • Compression: "gzipped" (or whatever you prefer... gzip makes smaller files)


TO RESTORE THE DATABASE

  • open phpMyAdmin
  • select the database you wish to restore into, from the dropdown menu
  • click on the Import tab (in older phpMyAdmin versions, you might have to click the SQL tab instead, to get the Browse button mentioned next: )
  • click on the Browse button, and select the file you downloaded when making the backup
  • click Go


DOING FILE BACKUPS

You will want to download an FTP client to transfer files. You can select exactly which parts of your server space to copy. Be aware of the progress of selecting - depending on program, connections and settings it is possible to time-out in the middle of a long selection process, and picking up where you left off risks missing or misaligning some files.

Some good FTP programs are: FileZilla and FlashFXP


Installing your site copy

[Copied from FAQs - tweaked for this use]

  1. On your local host, create a new MySQL database. Note the username, password, database name, and host name (usually localhost).
  2. On your local host do a fresh new install using the same version files that you built your other site on - this will make sure that you get the proper settings in your configure.php files. While installing, allow it to install the demo products, so that you can test and be sure that it's working nicely.
    • Install.
    • Test it.
    • Make backups of the local server's /includes/configure.php and /admin/includes/configure.php files by copying them to an easy-to-find place.
  3. Download a complete backup of your database and store.
    • Use either:
      • the "Backup MySQL Database" contribution under Admin->Tools to do the backup of your database, or
      • use phpMyAdmin to export your entire database ... include the DROP tables command, and under Data, choose Complete Inserts and Extended Inserts. Save the SQL file to your PC for later and note how to get to it.
    • Download all your old site's files via FTP (or if you have the option, zip them up on the server and download the zip)
  4. Now we need to deal with the files. There are two approaches you could take:
    • Upload your old files over the new files on the new server, with two exceptions:
      Don't overwrite the /includes/configure.php and /admin/includes/configure.php files on the new server.
    • (Alternate:)
      • If you are not confident about keeping the configure files from being overwritten, copy them to a safe place before starting, and then continue with the process above.
      • Replace the configure files if necessary after uploading is complete.
  5. Go back to phpMyAdmin on your new server.
    • Select your new database (that you installed the new Zen Cart™ into)
    • DROP all the tables. (Check them all and scroll down and on With Selected... select DROP. Confirm Yes.
    • Click on the SQL tab across the top and click Browse.
    • Select the SQL file you made in step 3a when you exported your old database, and click Go.
  6. Grab the "Fix_Cache_Key" utility to reset your Admin > Sessions > Session Directory key: Fix Cache Key Utility
    Simply upload the file to your new Zen Cart™ folder and open fix_cache_key.php in your browser. It will give you status messages. Delete fix_cache_key.php when you're finished.
  7. You're done. Open your store and Admin areas to see it all ready to go.