Thursday, May 9, 2013

Copy WordPress Website to Local PC


At one point you may want to have a copy of your WordPress website on your local machine. There are many reasons you may want to do this. You may want to test WordPress themes, plugins, or make changes to  your WordPress blog without the risk of messing up your production website. If you have a web server running on your local PC, like Apache or IIS, PHP installed and running, and MySQL, you can easily download your WordPress blog and run it on your localhost.

Follow these steps to get your WordPress site on your local machine.

Step 1:
Copy all files from your webhost to your local server folder. In most cases this will include the following files and directories.

directories
wp-admin
wp-content
wp-includes

files
all php files that begin with "wp-"
xmlrpc.php (if you have it)
index.php
webformmailer.php (if you have it)


Step 2:
On your web host, login to phpmyadmin and export your database (By Selecting your database and selecting the export tab and downloading to your computer). Be sure to check the option to create database.


Step 3:
Log into your local phpmyadmin or MySQL Workbench, and import the sql database.


Step 4:
Once the WordPress database is created in your local MySQL, you will want to modify the database to reflect the new blog location being on the localhost. So you will need to run the following SQL on your local MySQL.

Change "YOUR_DOMAIN" with your domain name

UPDATE wp_options SET option_value = replace(option_value, 'http://www.YOUR_DOMAIN.com', 'http://localhost') WHERE option_name = 'home' OR option_name = 'siteurl';



Step 5:
Now you want to fix the urls of posts and pages. So you need to run the following SQL on your local MySQL database:


Change "YOUR_DOMAIN" with your domain name

UPDATE wp_posts SET guid = replace(guid, 'http://www.YOUR_DOMAIN.com','http://localhost');



Step 6:
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. So we run the following SQL to fix this issue:



Change "YOUR_DOMAIN" with your domain name

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.YOUR_DOMAIN.com', 'http://localhost');



Step 7:
You now want to now modify you wp-config.php file on your local host. The easiest way to do this is to delete the wp-config.php file on your local host and then visit http://localhost in a browser.

Step 8:
Create a MySQL user for your WordPress database. For simplicity, use the same username that is on your hosted WordPress site. Grant it all rights, and assign it to the new WordPress schema(database).

Step 9:
With the dialog message that comes up click the 'Create a Configuration File' button. Then click the 'Lets Go' button on the next screen.


Step 10:
Fill in all of the fields:
Database Name: This is the name of the database in your local phpmyadmin
Username: This is your phpmyadmin username (usually root)
Password: This is your phpmyadmin username's password
Database Host: This is usually localhost
Database Prefix: normally is wp_ unless someone has changed it manually.


Step 11:
Click Submit, the wp-config file will be created and everything should work on the local host. Do not go through the WordPress set up.

Note: If you WordPress theme has a skin, you may need to reactivate it in order to get the skin working again.




No comments:

Post a Comment