As a WordPress bloggers, plugin developers or themes designers you should have a local server for a testing environment. In Ubuntu you can easily install apache and mysql as it is bundled in default installation cd. And in Windows you can use XAMPP as a handy web server (you can refer to my previous post Local Server For Testing Environment With XAMPP On Windows for more details). And you can use XAMPP for Mac as well. But the point is you need a local server environment to designing, developing and testing your WordPress blog before your go live.
So if you already have a live self hosted WordPress blog, it is very recommended that you use the current server data and files to test new plugins, new themes or whatever. So to use the current server data, you need to download the whole database and files to your local server, which i would make the step by steps instruction to make exact mirror of your live WordPress blog into local server installation.
Here is the step by steps guide to bring your WordPress blog to local server for testing environment, i’m assuming that you use CPanel as most hosting server using this:
Download database file
- Login to your server CPanel and go to Databases > PhpMyAdmin
- It will have another tab open PhpMyAdmin, select your WordPress database
- Choose Export tab and leave all the default choices
- Check the “Save as file” check box and press Go button
- It will take a while to download your database into single sql file
Download WordPress files
- Still in server CPanel, choose Files > File Manager, choose your wordpress installation folder and GO.
- The file manager will open in another tab.
- Usually your WordPress files is under public_html folder, but if you install your blog under subdirectory (example /blog), then it will under blog directory.
- Compress public_html or root of your WordPress files to gzipped compression.
- Download the compressed file via FTP client.
Extract the WordPress files
- Now we are working in your local computer
- Move the downloaded compressed file into your webserver default directory, usually it is under htdocs.
- Create the subdirectory under htdocs, called it any name you want, but in this example i use “blog”.
- Extract the compressed file to blog directory
Import database file
- Open PhpMyAdmin, it is usually http://localhost/phpmyadmin, but if you have it different then you should know where you installed it.
- Create a new database, i called it blog
- Choose blog database, and go to import page
- Select the downloaded databse file and import it
- After it finish, go to wp_options table and find “site_url” and “home” in options name
- Change it to http://localhost/yoursubdirectory, in this example it would be http://localhost/blog
Configure WordPress
- Open the blog folder and open wp-config.php
- Change database name, database username, and database password. In this example i’m using:
database name: blog
database username: root
database password: toor
Okay now you can login to your wordpress admin (wp-admin) and use same username and password as in your server. Now set the permalink to use the default permalink, as you don’t need it pretty permalink in your localhost. And then you can delete your .htaccess, because sometimes it wouldn’t work in XAMPP default installation. Now it is recommended to deactivate some plugins that you don’t need, such as wp super cache, hypercache, db backup manager, akismet (as no one will spam your localhost), wp stat, other stats plugin, and other plugins as you feel you don’t need it.
Now you have a complete mirror of your WordPress blog in your local server. You can play with it as you like, and test any plugins before your go live. Test and tweak your themes before you applied. Do as you want to do in your local testing environment. If it break, revert back to old database and files.
This was a great walk-through! Thanks!
Thanks so much Ivan. You really helped me understanding more on how things work. I wrote an article to thank you for your help as well:
http://webdesignlove.co.za/2011/01/16/how-to-back-up-your-wordpress-database-to-localhost/
Thanks mate, i have read it. And thanks for the credit too 🙂
This works great, but I'm having problems with my mod_rewrite engine. Every page other than the homepage (locally) redirects to the xampp control page (http://localhost/xampp/). I have everything that the live version of the site did (.htaccess, database, files, etc.) I can't figure it out!
Many thanks for the walkthrough.
I followed these instructions, and they mostly worked.
However, I ran into issues importing SQL tables to the local install.
1. It appears that some of the tables were not completely exported, as some of the tables in my local version showed fewer rows than the live versions. I attempted to download each table separately and then upload them one-by-one into my mirror database (which is pretty large). This didn't fix the problem either.
2. I do manage to get the theme showing along with the posts, but it seems that a number of post revisions are treated as posts themselves and then are included in the WP loop. I can't figure out what's going on.
3. After I log out of the mirror site and attempt to log back in, I'm told I don't have permission to access the administrative dashboard. I originally thought this might have something to do with the Role Manager plugin, but retrying the install without that plugin didn't help either.
I'm sure I must be doing something wrong. I know this is probably a vague and confusing list of issues, but I was wondering if you might at least be able to point me in the right direction.
Should I try to mirror only part of the site to cut down on the table sizes? Should I try checking different options than the defaults during export?
Again, many thanks. This is a nice guide. I must just be running a messy site.
Hi,
first make sure you dump your sql file perfectly. Use mysqldump instead of export from phpmyadmin. and don't forget to gzip.
Thank you again for the reply. I got sidetracked with other projects, but I will try mysqldump now that I've got some time again.
Hi Ivan–thanks so much for this! I've been trying to import a WordPress site onto my local machine so I can experiment with some CSS issues, and everything I found was so complicated! All I wanted to know was how to stop my files from referring back to the live site and you answered it! Thanks heaps for saving my sanity!!
thanks for the tutorial. I have a question. Everything went smooth with the migration, but if I choose to go with a %postname% permalink feature on my localmachine, I am getting an error message "The requested URL was not found on this server. " Any ideas?
Don't forget to download the .htaccess
Thanks for the tutorial. It is great!
Everything is fine but when I log into the wordpress admin the Apache server stops working. Any insights what can be causing this happens?
Cheers.
@ivantxo try to disable all the plugins. you can disable it by rename plugins folder to something else. And try to reload your page.
I was using Xampp version 1.5.5. I reinstalled Xampp version 1.7.4 and everything is working perfectly.
Thanks Ivan your tutorial is great!
Thank you Ivan for this great tutorial. Very useful. Keep posting useful contents and Good luck in your profession.
hello,
hope you can help me with this issue.. i follow your steps mentioned above…but i got a server error.. when i try to access my localhost directory / wp-admin…so i try to delete the table prefix value in wp-config file then it works but wordpress directs me to a new installation instead of the wp-login…any idea how to resolve this issue? much appreciated thanks!
mark