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 (if you’re going to upload images or contents in your local site)
For example, asuming 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: http://www.yoursite.com/wp-content/images –> http://localhost/wpconsole/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.











































Thanks for this, a clear concise tutorial for running a dev copy of Wordpress.
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.
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.
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!
Hi sun,
No worries. Let me know if I can be of any help.
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?
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.
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.
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
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
Yup, that’s right since you it’s located in a folder (htdocs/wordpress).
You will also need to change RewriteBase / to RewriteBase /wordpress/
[...] delle informazioni qui riportate sono state prese da Running A Duplicate Offline Copy Wordpress Site e Make a Backup Copy of your Production Wordpress Blog on Ubuntu :: the How-To [...]
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.
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!
Glad you found the solution.
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.
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.
ok, thank you David. I appreciate it very much. I will give this a shot and post my findings later.
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!
Glad you found it useful.
Why there is no mention of changing wp-config.php in main instructions?
Mukesh, there is. It is mentioned in step 6.
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.
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?
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
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.
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.
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
Thanks, but the advice is too late. I have burnt my finger already
[...] like to give credit where credit is due. Special thanks to David Tan of Davidtan.org and Alex from Lifespy.com for their equally informative tutorials on this subject though I felt [...]
Thanks! You saved me a lot of time figuring out why my site doesn’t work offline. I missed step #7
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!
Great article. Exactly what I was looking for. Worked perfectly. Thanks
Hey, thanks for this!
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.)
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.
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.
Thanks a lot for posting your solution, Tim.
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?
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!
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.
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.
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:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>Thanks for pointing me in the right direction David.
)
Test sites built on PCs cannot use .htaccess files. I think they only apply to *.nix based systems.
Tim, in fact .htaccess can run on Windows. Those all-in-one LAMP packages such as XAMPP and WAMP allows you to do that.
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 .
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.