WordPress local clone not working properly

I am developing a portal on WordPress and have a lot of plugins, posts, categories etc. in place. Now, I wanted to try three themes parallely.

So, I created two more copies of the folder in my local apache’s webroot as:

Read More
/wpSandbox/ [original, working still !]
/wpSandbox2/ [copy 1]
/wpSandbox3/ [copy 2]

Similarly, I replicated the database dbWordpress for the original portal using phpMyAdmin twice and then changed correspondingly in wp-config.php

Now, the two new copies (which I expected to be bases for testing the new themes) can’t login to admin.

In fact,

127.0.0.1/wpSandbox2/wp-admin/ 

actually redirects to:

127.0.0.1/wpSandbox/wp-admin/ 

and can’t log in using same credentials that work for the original copy… 🙁

Please tell me why this could be happening, is something else required to be altered in wp-config for the copies..?

Regards

Related posts

Leave a Reply

3 comments

  1. Chances are you need to update your database with the new URL. That’s why it is redirecting.
    Copy the code below and run it in phpMyAdmin (make sure you change the 3 variables at the top… I set them to what I think you should set them, but it could be different the way your database is set up)

    SET @prefix = "wp_";
    SET @old = "127.0.0.1/wpSandbox";
    SET @new = "127.0.0.1/wpSandbox2";
    
    SET @sql1 = CONCAT('UPDATE ', @prefix, 'options SET option_value = REPLACE(option_value,?,?)');
    SET @sql2 = CONCAT('UPDATE ', @prefix, 'posts SET guid = REPLACE(guid,?,?)');
    SET @sql3 = CONCAT('UPDATE ', @prefix, 'posts SET post_content = REPLACE(post_content,?,?)');
    
    PREPARE update1 FROM @sql1;
    PREPARE update2 FROM @sql2;
    PREPARE update3 FROM @sql3;
    
    EXECUTE update1 USING @old, @new;
    EXECUTE update2 USING @old, @new;
    EXECUTE update3 USING @old, @new;
    
    DEALLOCATE PREPARE update1;
    DEALLOCATE PREPARE update2;
    DEALLOCATE PREPARE update3;
    

    Gist: https://gist.github.com/doitlikejustin/6091841

    Just a bit of info on this code/Gist… I move WordPress sites ALL the time. This is just some SQL that I have written so that updating the database takes less time and you don’t have to worry about manually updating URL’s. It automatically updates the WP options table and WP posts table.

  2. The redirection problem is because of siteurl in your original wordpress settings. Add these lines in you wp-config.php. You may have to change the url to suite your needs.

    define('WP_HOME','http://127.0.0.1/wpSandbox2');
    define('WP_SITEURL','http://127.0.0.1/wpSandbox2');
    
  3. update as_options set option_value=”{new_wp_url}” where option_name=’siteurl’;
    update as_options set option_value=”{new_wp_url}” where option_name=’home’;
    UPDATE as_posts SET guid = REPLACE(guid, ‘{old_url}’, ‘{new_url}’)
    UPDATE as_posts SET post_content = REPLACE(post_content, ‘{old_url}’, ‘{new_url}’)

    Below is the SQL query that you can run to change the values to new url for wordpress sites.

    UPDATE {wp_table_prefix}_options set option_value="{new_url}" where option_name='siteurl';
    UPDATE {wp_table_prefix}_options set option_value="{new_url}" where option_name='home';
    UPDATE {wp_table_prefix}_posts SET guid = REPLACE(guid, '{old_url}', '{new_url}');
    UPDATE {wp_table_prefix}_posts SET post_content = REPLACE(post_content, '{old_url}', '{new_url}');
    
    • Replace {wp_table_prefix} with your wordpress table prefix.
    • Replace {{new_url}} with your new wordpress site url.
    • Replace {{old_url}} with your old wordpress site url. In this case 127.0.0.1/wpSandbox

    After that you can run the SQL query and access the new wordpress site at your new wordpress url. And everything should work fine.

    I have been using above SQL frequently and has worked for me so far. If you have any problem, then let us know. Basically the above SQL queries are equivalent to @doitlikejustin code provided above.