There are cases where having and running your complete wordpress site offline in your local machine can be useful:
1) To run as a backup.
2) To write a new theme just for your site.
3) To test out new plugins before you plug it into your real live wordpress (online) site.
3) To talk to yourself where no one cares what you say, and reply to your own comments if you wish
4) and best of all, to mess with the database with phpmyadmin.
1. First of all, you need to backup all the contents of your live wordpress site using the WordPress Database backup plugin (Read my Top 10 Most Wanted WordPress Plugins)
* I would recommend the core wordpress tables to be backup only, namely:
– wp_comments
– wp_links
– wp_options
– wp_postmeta
– wp_posts
– wp_term_relationships
– wp_term_taxonomy
– wp_terms
– wp_usermeta
– wp_users
2. Get yourself a copy of Xampp. I use the lite version personally, but you can get the full version if you want. Extract it into C:\ (assuming you’re using windows)
3. Install wordpress into C:\xampp\htdocs\wplocal (or anything you like in C:\xampp\htdocs\)
4. Start xampp. Using your browser, goto http://localhost/phpmyadmin. Create a new database (ex. wplocal)
5. Import the SQL script created from step 1 into the database you’ve just created (ex. wplocal) from phpmyadmin
6. Edit wp-config.php so the local wordpress knows which database it will be using.
7. This part is important
Up till this stage, all we’ve done is getting our data from our live site into a database stored locally. The site is already runnable locally, but you need to change these 3 fields in the wp_options table (to ensure you won’t be directed back to your live site when you test locally):
– siteurl
– home
– fileupload_url (for wordpress 2.x) or upload_path (for WordPress 3.x) (if you’re going to upload images or contents in your local site)
For example, assuming that you have wordpress in C:\xampp\htdocs\wplocal, in wp_options, update:
siteurl
http://www.yoursite.com –> http://localhost/wplocal
home
http://www.yoursite.com –> http://localhost/wplocal
fileupload_url (for wordpress 2.x) or upload_path (for WordPress 3.x)
http://www.yoursite.com/wp-content/images –> http://localhost/wplocal/wp-content/images
8. That’s it. Goto http://localhost/wplocal and enjoy your local wordpress site with all the contents. The next time you make your backups, exclude wp_options since you don’t want to change the options again.
9. If you really like the theme you use in your live site, download it and put it into C:\xampp\htdocs\wplocal\wp-content\themes. Select to use the theme. Now, you have a total 100% duplicate of the content + presentation.
10. Try it out yourself. You can even run wordpress locally as your personal diary.
J says
Thanks for this, a clear concise tutorial for running a dev copy of WordPress.
sun says
Hi David,
You got a very detailed tutorial here. I have some problems here. After following through your steps, I got my site up offline. I can see my page, the index page I think. However, if I click on any of the link to go into any single post, of page, it will return me “Object Not Found error”. I am not sure which part that I could have done wrong……
I use WordPress Database Backup plugin instead of what you mentioned.
Thanks.
David says
Hi sun,
I used WordPress Database Backup Plugin too to get a sql backup dump of my wordpress site too so I think we’re both the same for this part.
I’m not too sure what caused the “Object Not Found Error” message you’ve got there but thinngs to look at are you’ll need a local web server with php and mysql installed (I use XAMPP for that).
Did you also restore the sql backup into mysql?
Don’t forget step 7 above as well as I’ve persoanlly missed this before and all your post + pages will still link back to the live site as a result.
sun says
Hi David,
Yes, I did all the steps…… Lost now coz I am not sure which part is wrong. But I think I will just start a fresh database, copy a few old post into it for the time being since I just want to edit a theme to suit my needs.
Thanks!
David says
Hi sun,
No worries. Let me know if I can be of any help.
nate says
I’ve done all these steps and when I go to http://localhost/wplocal a download box pops up saying:
You have chosen to open
which is a: application/x-httpd-php
from: http://localhost
What should Firefox do with this file?
Open with
Save Files
Did I miss a step?
David says
That’s strange, because if you’re using xampp, this part should have been handled properly.
I would assume that you had installed apache, php and mysql manually. If that’s the case, you can probably check php4.conf or php5.conf to see if they contains the following lines:
AddType application/x-httpd-php .php .phtml .php3
AddType application/x-httpd-php-source .phps
AddType application/x-httpd-php .php4 .php5
Hope that helps.
nate says
I forgot an important part that may be worth mentioning, I think it’s Sun’s problem too: Permalinks
My site links weren’t working either and I’d get an Object Not Found page, so I changed my Permalinks (from within my localhost wpadmin) back to “Default,” they were set at “Date and name based” from my original site settings. Doing that fixed the link problem.
Then I deleted my .htaccess file that was in my folder (from when I copied over my blog) and that fixed the download box popping up. Now everything works great, thanks David.
David says
Sun and Nate, I’m 100% sure that I’ve found the cause and solution for the “object not found error”.
The problem lies in the fact that, by default xampp apache’s httpd.conf commented out mod_rewrite, which basically means that all your permalinks wil die since no url rewrites can be done. We need to have mod_rewrite turned on so that our pretty permalinks can work.
So, goto apache/conf/httpd.conf and remove the # in front of the line
LoadModule rewrite_module modules/mod_rewrite.so
That would fix it 🙂
Internet Marketing Service says
I had the same problem but my httpd.conf file had already removed the # in front of the line LoadModule rewrite_module modules/mod_rewrite.so
I found out that the .htaccess file in my directory c:/xamp/wordpress needed to be changed. Here “wordpress” is the folder within the xamp installation.
In the .htaccess file, change the following line in the mod re_write rule:
RewriteRule . /index.php to RewriteRule . /wordpress/index.php
David says
Yup, that’s right since you it’s located in a folder (htdocs/wordpress).
You will also need to change RewriteBase / to RewriteBase /wordpress/
selcan says
Even though I’ve updated the wp_options table, i get redirected to my live site while testing locally. its not a problem if i do things locally using the dashboard. if i add a post via dashboard locally i dont see it on the live site but if i click on any link in the local site (like when i try to add a comment) i get redirected to live site so my comment gets added to live site instead. I noticed that in the wp_posts table, there url of the links are listed with the live site address. Please let me know if i’ve missed something.
selcan says
nevermind! i hadn’t changed the home field because i had to scroll to the next page of the table to do it, now it works!
David says
Glad you found the solution.
Mike says
David, hi… thanks for making this info available.
I made the diary happen. but I’m having problems making the copy of my wordpress site on the local pc. I think the answer should be simple, if you have a second…
I created a folder inside the c/xmapp/htdocs folder for my diary, called “diary”. That works fine. Then I created another folder in that same directory called homelocal, which is supposed to be the mirror of my website. I followed all the steps to a T here. Now, when I type in the URL hxxp://localhost/homelocal… the name of the site is actually “diary” and it should be “frank jr”… and the content is simply the content of a fresh new wordpress installation (not the content of the diary). But the whole site should be frank jr with the associated information that I imported into the SQL database.
The wp-config files have been edited to point to the correct database name in both cases… the do share the same username and password, however, (which is the same username and password that I set up to log into the MYSQL page.) In the phpmyadmin, there doesn’t appear to be a way to give each database you create their own username and password (like my web hosting place does).
Any old idea you might have would be much appreciated.
David says
Hi Mike,
You are fine with just using one username (usually root) and password, don’t worry about it.
You did say that homelocal wp-config is pointing to homelocal database, so that part should be fine. It’s either you have
1) loaded the wrong database (ex. the diary’s db into homelocal db) or
– solution: load the right thing
2) homelocal database’s tables contains settings which tells it to redirect to diary’s page
– solution: look into homelocal’s database and refer to step 7, and make sure those targets goes to hxxp://localhost/homelocal instead of hxxp://localhost/diary
BTW, what do you see in the address bar when you browse to hxxp://localhost/homelocal? If it changes, then you probably need to look at step 7 again.
Mike says
ok, thank you David. I appreciate it very much. I will give this a shot and post my findings later.
Johnathan says
Thank you so much for taking the time to make this available. You really saved me a large amount of time I would have spent hunting for those changes in the wp_options table. Keep up the good work!
David says
Glad you found it useful.
Mukesh says
Why there is no mention of changing wp-config.php in main instructions?
David says
Mukesh, there is. It is mentioned in step 6.
Mukesh says
Hmm. I must have missed somehow. You may also think of educating people about $_SERVER[HTTP_HOST] in wp-config.php and issues related to that. In the search of the thing that I came here. I came across other posts which talked about those variables, and that method seems quite neat. No need to exclude tables and all that.
David says
Thanks Mukesh. I’m not aware of doing anything fancy with $_SERVER[HTTP_HOST] in wp-config.php. Maybe you can share it with us on where you find that?
Mukesh says
Sure. Please check following links to get an idea.
http://blog.ohohlfeld.com/2008/06/infinite-301-redirect-loop-in-wordpress-due-to-canonical-urls-fixed/
http://www.nabble.com/When-HTTP_HOST-does-not-point-to-the-blog-td18097138.html
David says
Cool, will need some time to read through them 🙂
Although I doubt novice users will go into that detail just to get wordpress running locally. Did you get wordpress to run locally with my guide or the guides mentioned in your reply? Nice information nevertheless.
Mukesh says
Actually for novice users $_SERVER solution is better. Just change few lines in a file instead of so many steps. Also, it is only one time. One doesn’t need to perform those steps every time website is uploaded.
In my case I had wordpress installed locally, and when I was trying to upload my website to the webhost, I saw that I am having to change wp-config.php, and entries in db (by doing dbdump etc.) to be able to have things running smoothly. But it was quite painful actually, so I googled to find a solution and came here. And found that you are also going through the pains 🙂
So I vouch for the other solution 🙂
On the side note:
One of the things that irritated me most in wordpress is if I change site url (using wordpress admin interface) to something junk, then I won’t be able to login itself next time. phpmyadmin also doesn’t work (if u want to change that entry back to some sane value). Some non geeky solution should be given by WordPress for that.
David says
That’s interesting. Your situation is a bit different from what I had set out to do when I wrote this post. You’re actually testing out your wordpress locally before uploading to a web host. In my case, I had a running wordpress on my web host, and wanted to download it and have a running backup locally.
My advice would be don’t try changing siteurl to something junk if you can help it 🙂
Mukesh says
Thanks, but the advice is too late. I have burnt my finger already 🙂
Pawel says
Thanks! You saved me a lot of time figuring out why my site doesn’t work offline. I missed step #7 🙂
Bryce Finney says
I also had the 404 not found problem. The problem in my particular case seems to be that because my wordpress blog isn’t in the root directory of the folder it’s in (eg, on my site it is located in mysite.com/home/) Apache was looking in the wrong location for it. I needed to change my httpd.conf file’s DocumentRoot to add the the subdirectory. Everything seems to be working fine now. Thanks for this great write-up. Also, don’t forget to check your Apache error log folks!
brian says
Great article. Exactly what I was looking for. Worked perfectly. Thanks
matt nathanson music fan says
Hey, thanks for this!
Tim M Beckwith says
This is both a good write-up and discussion. But I am having a result and problem which does not seem to be addressed here.
I followed all of the directions given including a careful following of step #7. In my local PC’s htdocs directory I set up a sub-directory specifically for my WordPress blog. That sub-directory is called “oflansblog”. All of my WordPress directories (wp-admin, wp-content, & wp-includes) and files are located in that directory. When I enter “hxxp://localhost/oflansblog” (w/o quotes, natch) in my Firefox browser my blog’s homepage comes up just as expected. But it also prints this line at the very top of the page:
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-content\plugins\bad-behavior\bad-behavior\screener.inc.php on line 8
Furthermore, when I log into the dashboard of my site I get a whole page of:
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-content\plugins\bad-behavior\bad-behavior\screener.inc.php on line 8
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-login.php on line 302
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-login.php on line 314
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-includes\pluggable.php on line 665
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-includes\pluggable.php on line 666
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-includes\pluggable.php on line 667
Warning: Cannot modify header information – headers already sent by (output started at F:\xampp\htdocs\oflansblog\wp-content\plugins\all-in-one-seo-pack\aioseop.class.php:4545) in F:\xampp\htdocs\oflansblog\wp-includes\pluggable.php on line 868
The dashboard becomes useless and not accessible. I can’t do anything. Any suggestions as to how I can fix this problem? (My production site works just fine.)
David says
I think there are 2 ways to solve your problem:
1) On your local machine with wordpress, disable the plugins “all in one seo pack” and “bad behavior” or
2) download both “all in one seo pacl” and “bad behavior” , install them into your wp-content/plugins folder, and activate them
Let me know if that helps.
Tim M Beckwith says
I wasn’t able to do either of those two suggestions because once I logged in to the WP “backend” the page fills up with the messages cited earlier and is not available. I could not disable or install anything.
But your suggestions gave me a very good clue. No where in the discussion up to now has anything been said one way or another about downloading the plugin folders (directories) from your installed production site to your home test site. Since I wanted a test site which started out (at least) to be identical in appearance and operation to the production site, that is exactly what I did. I even took the additional step of going through my test site’s wp_options table and updating EVERY field which contained path references to the production site. A tedious task made less burdensome through the careful use of copy and paste.
That was my big error! Don’t do that. Do not copy your plugin folders from your production site to your test site. That is what generated all of the error messages I was getting on my frontpage and backend page (after login).
Once I went in and tore out all of my existing plugins from the test site (being careful to leave in akismet which is installed when you install wordpress on your test machine) all of the error messages were cleared out. My normal dashboard was re-established.
Of course that means I’ll now need to manually install new plugins to match those on the test site to match those on the production site. But, since my test site is not accessible to the outside, I can probably leave out many of the security-related ones.
Thanks for your time and suggestions.
David says
Thanks a lot for posting your solution, Tim.
Fred says
I have tried everything that is written here but alas, I cannot get the blog I am working on to run locally; well, not properly anyway.
BTW, I am using WP v2.9.1 and WP is installed in the root (using WAMP).
The first thing, I do not have a fileupload_url field in the wp_options table. There is a upload_path field but it uses a literal path from the root, not a http path. None the less, I changed this to hxxp://localhost/wp-content/uploads
Now, the blog runs and I can access the admin interface locally but when I click on any comment balloon in the blog I get a 404 error. The path in the location bar looks to be correct (same as the live site but with localhost) but I cannot access any of the comment pages.
The URL is something like hxxp://example.com/2010/01/some-comment/ on the live site and hxxp://localhost/2010/01/some-comment/ on the local site.
Now, there is no folder under the root called 2010, so this must be some form of alias. How do I configure the local setup to use the same alias? It’s got me stumped.
Can anyone help?
Fred says
I should add, I am using a mirror copy of all of the live site’s files (an FTP download of all WP files).
Unlike Tim, I do not get any errors viewing the main page of the blog, all other pages however… cannot get to them!
David says
Hi Fred, I’ve got 2 suggestions, with 1) being the most likely solution:
1) Check whether you have mod_rewrite enabled (in WAMP > php.ini)
2) check what you have in localhost\.htaccess and see if it’s pointing back to your live site, and change it to point to your local copy if it is. I would assume that you’re save to just delete this file and local wordpress would still work anyway, but you might want to backup before doing that.
FYI, you will never find the folder 2010. It’s virtual and can only be run when mod_rewrite is enabled on the server.
Fred says
Thanks for your suggestions David.
From what I have read, you cannot enable mod_rewrite via the php.ini file. If you know how, maybe you can share…
I did enable mod_rewrite in the Apache httpd.conf file however and confirmed it was enabled by running phpinfo.
Alas, I still have the same problem.
Any other ideas?
BTW, I do not have a .htaccess file in the web root.
Fred says
Problem solved…
For anyone interested, or experiencing the same problem, here is my solution:
Enable mod_rewrite in the Apache httpd.conf file.
Create a .htaccess file and include the following code:
Thanks for pointing me in the right direction David. :o)
Tim M Beckwith says
Test sites built on PCs cannot use .htaccess files. I think they only apply to *.nix based systems.
David says
Tim, in fact .htaccess can run on Windows. Those all-in-one LAMP packages such as XAMPP and WAMP allows you to do that.
Tim M Beckwith says
Fred —
Go back to the upload_path field in your wp_options table. Set the value there to simply “/wp-content/uploads” (without quotes, of course).
That change on my PC WordPress install made the “../2010/01..” error messages go away, but did not totally fix my situation. I could then upload pics to my test site’s media library ok. I could even add them to my posts from there. But I could not actually see any pictures so uploaded. That function only worked correctly on my production WordPress install. But that, of course, is housed on a linux box.
Still, the test site enables me to layout a longish post, view how it lays out on a “published” test page, tweak and perfect it, then, when generally satisfied, copy and post the whole thing to the production site. Where I can post my pictures. Like for this page http://oflanagans.net/?p=161#more-161 .
Fred says
Tim,
Thanks for your suggestions.
All I can say is that with the two changes I have made now that my offline blog is now fully functional.
This is not my blog, rather a colleague’s that I am doing some “tweaks” on. Previously, making changes on a WP install with the same theme yielded mixed results. Now that I have a working “clone” all of the changes I have done lately also work on the live site.
julian says
exactly what i want…
i will try
thanks
Shivam Patel says
Hey David,
Thanks for this lucid tutorial. This is immediately going into my bookmarks !!
I really appreciate the way you have kept troubleshooting people’s followup questions.
Great work !!
Mommy Meeting says
I followed the instructions here, but when I visit my http://localhost/wordpress site it is a blank page. Can’t seem to figure out why it isn’t displaying my mirrored site. Any ideas?
David says
The first thing to check is whether xampp has already been started (check that apache and mysqld is running in task manager specifically).
David says
I had exactly the same blank screen problem. Everything else worked fine. In my case, I found the problem was due to not having an active theme associated with the WordPress install. I solved the problem by installing a new theme.
mitch says
Your tutorial is very well explained and it worked for me. Thanks for posting this very useful information.
Adam says
David, thanks so much for this step by step guide. I’ve managed to get an identical local copy of my site up and running in half an hour!
Keep up the good work and thanks again 🙂
Adam
Rosco says
Hi David, Nice article.
I just followed your instructions except I did it on Mac using MAMP instead of XAMPP. Works prefectly.
Thanks
Rosco
Josh says
I’ve got a convoluted web setup, with an extra admin login, renamed root user for PHPMyAdmin, wp-config.php above my root, and many plugins, including W3 Total Cache. Don’t know what’s messing with what, but I can only ever access my homepage when I try to migrate to localhost (in XAMPP). All other pages redirect to my XAMPP home page. I’ve tried deleting my .htaccess and restoring it to the basics (like above), but that hasn’t helped. Anyone else had this problem and found a solution?
Josh says
Actually found that changing permalinks on my site to default solved the front-end problem, but I still can’t get into my back end on localhost.
Josh says
Only way I could see to resolve that was to rename the .htaccess file within my wp-admin. Tried changing the path to the .htpasswds files, but no luck.
eugene says
hey dude. i can’t find the fileupload_url in the wp_options table. any tips on that one? i was able to make the offline copy though.
thanks for the help!
David says
fileupload_url seems to have vanished in WordPress 3.
Instead of looking for fileupload_url, try upload_path
Eugene Fabian says
yikes. it seems that i can only make the front page work locally. whenever i go into some links, it doesn’t work. I can go into the admin panel though. hoep you can help!
thanks!
David says
Eugene,
sounds like your “links” are absolute links, meaning they are in the form of http: // yourlivesite.com /post-title-bla when you write them in your post.
If those links were “relative links” such as /post-title-bla when you write them in your post, your site and content will still work locally.
To replace all “absolute links” to “relative links” in your post content, use the following sql:
Hope that helps.
Kevin Watkins says
This worked for me too, now I can tweak my theme and visitors won’t see things when they go wrong! Thanks.
Alberto says
I have set up my offline blog. Everything works fine, except for the plugins. When I first start admin panel and go to the plugins tab, it deactivates all the plugins. If I try to install a plugin from a zip file, it correctly installs it in the plugins folder. However, all the other plugin folders are not seen.
Do you know why?
David says
Plugins that you have on your live blog will need to be manually downloaded/copied into your offline/local blog at wp-content/plugins.
Alberto says
I already downloaded them. Just my offline installation doesn’t “see” them. They are all in the plugins folder.
Sebastien says
Hey David,
exactly what I was looking for!
I was wondering if it will be as simple to upload the local changes back to the site ?
How will I go about this (if same plugins are used, and modified, some post, etc ?)
If I can avoid duplicating my tasks, that would be neat 🙂
Thanks
S.
David says
Hi Seb, I would say that’s it’s the exact the reverse of what we’ve done so far.
1. take a sql backup of your whole “localhost” wordpress database
2. restore the sql backup into your live site / webhost
3. After restoring the sql backup on the live site/webhost, goto wp-options table, change table columns that starts with http://localhost/ to http: // http://www.yoursiteurl.com or http: // yoursiteurl.com
Hope that helps. Let me know if you’ve other ideas and if it works on your side.
enchance says
It works! Just what I was looking for.
n0ta says
Fantastic short info! Very helpful!