Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

/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

like image 410
Nikhil Khullar Avatar asked Aug 22 '26 01:08

Nikhil Khullar


1 Answers

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.

like image 90
doitlikejustin Avatar answered Aug 23 '26 14:08

doitlikejustin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!