3

I have tried copying my wordpress site to my PC for editing offline using WAMP. I followed the following tutorial word for word.

How to create a local copy of a wordpress site

I have placed my files in C:\wamp\www\wordpress

I saw somewhere about adding the following to the wp-config.php but it still points to my website.

define('WP_HOME','http://localhost/wordpress');
define('WP_SITEURL','http://localhost/wordpress');

I am 100% sure that wp_options table in my database only references http://localhost/wordpress so where is it getting my live site address from?

UPDATE 1: I just noticed the following in the bottom of my wp-config.php

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
 define('WP_DEBUG', false);

 define('WP_ALLOW_MULTISITE', true);
 define( 'MULTISITE', true );
 define( 'SUBDOMAIN_INSTALL', false );
 $base = '/';
 define( 'DOMAIN_CURRENT_SITE', 'www.mywebsite.co.uk' );
 define( 'PATH_CURRENT_SITE', '/' );
 define( 'SITE_ID_CURRENT_SITE', 1 );
 define( 'BLOG_ID_CURRENT_SITE', 1 );

 /* That's all, stop editing! Happy blogging. */

 /** Absolute path to the WordPress directory. */
 if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');

 /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');

where it says

define( 'DOMAIN_CURRENT_SITE', 'www.mywebsite.co.uk' );

(obviously changed my address for posting) if I change it too

define( 'DOMAIN_CURRENT_SITE', 'localhost/wordpress' );

I get a redirect loop. Is this related or am I changing something I don't need to and the issue is else where?

UPDATE 2: does it having anything to do with the fact that on my website the wordpress files are in the www folder and on the local they are in the www/wordpress folder?

4
  • Have you modified the database?
    – user35560
    Commented Aug 4, 2013 at 11:18
  • As I already mentioned above, yes I have modified the database
    – Gaz83
    Commented Aug 4, 2013 at 12:25
  • You should add http:// to localhost define( 'DOMAIN_CURRENT_SITE', 'localhost/wordpress' );
    – Joe Buckle
    Commented Aug 4, 2013 at 15:17
  • @JoeBuckle just tried, no difference.
    – Gaz83
    Commented Aug 4, 2013 at 15:40

6 Answers 6

3

I have found the answer... well to my situation anyway. It was something related to multisite. Removing the following from wp-config.php got it to work for me.

Removed

define('WP_ALLOW_MULTISITE', true);
define( 'MULTISITE', true );
define( 'SUBDOMAIN_INSTALL', false );
$base = '/';
define( 'DOMAIN_CURRENT_SITE', 'www.mywebsite.co.uk' );
define( 'PATH_CURRENT_SITE', '/' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Although I had mine setup for multisite I wasn't really using it so I thought I would try and set it up as single site. As soon as I tried the above it worked.

2
  • Ok. Good that you got the answer. :) Commented Aug 6, 2013 at 5:43
  • You can accept your answer now by clicking on the checkmark. :) Commented Dec 1, 2014 at 3:42
2

Update

Instead of find-replace string using Notepad++ (or any editor) a better way would be to use a plugin which does the same job in a safer way — a way where the serialized data would be intact during the migration:

Use plugin like the Velvet Blues Update URLs. The plugin can be used for migration from localhost to live server or vice versa. Josh Hall has a video on that:

🎬 Video: How to MANUALLY Migrate Your WordPress Site - Josh Hall


I follow an easy process taught by my colleague and teacher Ms. Tahmina Aktar. The process is:

From webserver to localhost migration

From the server cPanel File Manager:

  • Step I: Select All the files in your WordPress installation
  • Step II: Compress them into a zip file (.zip).
  • Step III: Download the .zip file into your local server (for WAMP, it's www), and Uncompress it.
  • Step IV: From cPanel's PHPMyAdmin browse the related database and export all the tables as a .sql file. (i.e. mysql.sql)
  • Step V: Open the mysql.sql file with tables and data into NotePad++ (Because NotePad++ won't make your system lazy or idle even if the DB is huge)
    Now press Ctrl + F to Find, and on the text box, type: "http://www.mywebsite.co.uk" and then click on the Replace tab, and type: "http://localhost/mywebsite".
    Now find and replace individually or you can find & replace all.
    And then Save the file mysql.sql.

NOTE: Remember the Forward Slash (/) at the end of the URL. If you typed http://www.mywebsite.co.uk/ in find box, then of course type http://localhost/mywebsite/ in the replace box. Otherwise the file structure can be broken, like: mywebsitewp-content/themes/... or mywebsite//wp-content/themes/....

  • Step VI: Make a new database (i.e. my_db) in your local server (i.e. WAMP PHPMyAdmin), and Import the mysql.sql into the db.

  • Step VII: Open the WP-Config.php into your editor, and change the following lines into:

    /** The name of the database for WordPress */
    define('DB_NAME', 'my_db');

    /** MySQL database username */
    define('DB_USER', 'root');

    /** MySQL database password */
    define('DB_PASSWORD', '');

    *(or the settings you have in your localhost)*
    
    Save the file and Browse your site in localhost freely.
    

From localhost to web server migration

If you need to launch your site to the web from the localhost, just follow the procedure alternatively.


Let's talk about your problem:
Now, you got the idea of how you can manage your database for the local server and the remote server simply by replacing the relative URLs in the correct form and directory path. So, you can search your DB in NotePad++ if there are any web-related mentions there, you need to replace.

Good luck. :)

6
  • That's basically the same as the tutorial that I followed
    – Gaz83
    Commented Aug 5, 2013 at 20:30
  • Try the whole thing again. I think you made an unwanted mistake anywhere. Or, confirm that, there is nothing like the word "mywebsite.co.uk" (you know it's not as it is mentioned) is not present in your db. Commented Aug 6, 2013 at 5:41
  • 1
    this worked for me, thank you
    – BritishSam
    Commented Apr 11, 2020 at 10:10
  • 1
    Careful with the Notepad++ search and replace - any serialised data in the database will become unusable unless the replace string is exactly the same length as the search
    – Bysander
    Commented Oct 28, 2020 at 18:13
  • Thank you @Bysander. It was an old answer. Thank you for your feedback. Updated the answer a little bit. :) Commented Oct 29, 2020 at 13:05
0

Try logging in to the local WP installation as an admin. Now go to the dashboard, click "Settings" and change "WordPress Address (URL)" and "SiteAddress (URL)." Make sure you're logging in to the local WP database and not the live one!

6
  • thanks for the reply. I can't login to wordpress. If I type in localhost/wordpress it takes me to my live site www.blahblahblah.co.ukand if I try localhost/wordpress/wp-login.php that too also takes me to my live site.
    – Gaz83
    Commented Aug 4, 2013 at 17:05
  • Right. Well then, I would suggest setting up an Apache virtual host for www.blahblahblah.co.uk. This will force Apache to look for that URL at 127.0.0.1. A Google search should pull up plenty of tutorials on how to do this.
    – Neil Girardi
    Commented Aug 4, 2013 at 17:29
  • Thanks for that, I will give it a try now and report back
    – Gaz83
    Commented Aug 4, 2013 at 17:58
  • ok I followed this tutorial link and now I get Error establishing a database connection
    – Gaz83
    Commented Aug 4, 2013 at 20:16
  • Did you set up a local database? If you want to work on a local copy of your WP site you need a local copy of the DB in addition to a local copy of the WP php files. If you have not done this, please so do. If you have done this, please edit your wp config file so that it has the correct credentials to connect to you local DB.
    – Neil Girardi
    Commented Aug 4, 2013 at 20:55
0

My suggestion is download all your files associated with site as a zip and extract to localhost.

Add a plugin named wp-migrate. http://wordpress.org/plugins/wp-migrate-db/ ativate it.

Go to Tools -> Migrate DB

Enter your localhost url in the place of new address.No '/' required at the end.

New file path as the path in local system: eg: D:\wamp\www\

Click on Export Database.

Create a database and import the sql that your exported using the plugin to the created database.

Change the host, databasename, db username and dbpassword in wp-config file.

Hope this will help you. Thank you :-)
0

I just had the same exact issue, add a / to the end of your site url and home in your config and database, also check for whitespace at the end of your config file and remove it.

0

For a multi-site setup check your wp_blogs table. The domain field there likely contains a reference to your live site and is the culprit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.