Support » Localhost Installs » Editing SQL database for local site

  • I’m trying to copy a live site to localhost with WAMP.
    These are the steps I’ve taken so far:

    Downloaded site files via FTP. NB. These were not in the /public_html folder but rather a subfolder called :
    /public_html/revamp
    Copied these files to
    C:\wamp64\www\safc2018
    (I want to get rid of the [revamp] level.)

    Edit the wp-config.php file changing the DB_name to safc2018 as well as the username and password.

    Export the live site’s database via the host’s control panel as a .sql file.

    Build new local database in phpMyAdmin and import the live site’s .sql file.

    Use the following code to rewrite the URLs for the local site.

    UPDATE wp_options SET option_value = replace(option_value, 'http://www.yoursitename.com', 'http://localhost/newsite') WHERE option_name = 'home' OR option_name = 'siteurl';
    UPDATE wp_posts SET post_content = replace(post_content, 'http://www.yoursitename.com', 'http://localhost/newsite');
    UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.yoursitename.com','http://localhost/newsite');

    I’ve tried changing [yoursitename.com] and [newsite] with and without reference to the extra [revamp] folder, and I’ve tried putting the live site’s files in the following directories …
    C:\wamp64\www\safc2018
    C:\wamp64\www\safc2018\revamp
    C:\wamp64\www\safc2018\public_html\revamp
    … but can’t find a combination that works.

    Please can someone advise on a file location and datbase changes that will work?

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Eric Amundson

    (@sewmyheadon)

    Volunteer Moderator

    Howdy @eyeghoti,

    Wow, I’ve been in your shoes before and these issues can be really frustrating.

    In troubleshooting, I try to break it down to fixing, or eliminating, one issue at a time.

    The first, and most important issue is to make sure your DNS is resolving correctly.

    An easy way to test to make sure your local domain is routing correctly, you can put a static HTML file with the following code in the root of your WAMP site’s folder named as index.html. Then, type your local dev domain in a browser and make sure you see that file.

    I’d just put something very simple in that index.html file like:

    <html>
    <h1>You're in the right place!</h1>

    One you verify that you’re being routed to the right folder (you see your index.html file when using your domain), you’ll know exactly where to put your WordPress files. Make sure they’re in that folder and remove or rename the index.html file.

    The next issue is testing/fixing your database connection. Are you connected, or have you connected to the database successfully, or are you getting database errors?

    One thing I’ve done is to re-import the database, or setup a fresh database and import the data from your backup. Then, I’d open WAMP’s phpMyAdmin and and browse to that site’s options table. It’s likely named something like wp_options.

    Once you find that table, browse the table and you’ll find two entries – one for the home_url and one for the site_url. Set both of these to your local dev domain and save your work.

    Then, try to access and log into the site.

    Once you log in, then I’d recommend using a tool like Better Search Replace to search your newly-imported database for your old domain and replace with the new domain.

    The great thing about Better Search Replace is that, by default, it does a dry run for your search and replace so you can see how many occurrences of the old URL exist in the database before you do an actual search and replace.

    Let me know how it goes.

    @eyeghoti

    This is the simplest and easiest way to copy a site from one place to another. No messing around with databases and search & replaces – it’s all done “automagically” 🙂

    https://wordpress.org/plugins/all-in-one-wp-migration/

    I use this for all of my site moves 🙂

    Cheers!
    Lyle

    On the other hand, rather than using “localhost” in your locally hosted URLs, I would use the “VirtualHost” technique. Have a look at all the “.htaccess” files on your hosted site to see how the directory is mapped.
    Using the VirtualHost technique you don’t have to change the URLs in your database at all.

    Into your apache configuration you would add a block something like:

    <VirtualHost *:80>
    DocumentRoot C:\wamp64\www\safc2018
    ServerName yoursitename.com
    ServerAlias www.yoursitename.com
    </VirtualHost>

    And add your name to the “hosts” file, details here:
    http://en.wikipedia.org/wiki/Hosts_%28file%29

    Thanks all.
    I’m afraid some of this was beyond my understanding, but I resorted to All-In-One-WP-Migrationin the end, which worked. (I’d tried a couple of migration plugins before but they were either failing to transfer media files or plugins.)

    From that process I’m wondering if it was something to do with permalinks, but that’s only a guess.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.