I have tried to duplicate a local copy of my WP project, but have run into a snag, and can’t figure out what I did wrong.
After following all the steps to copy my local site1 install to a local site2 location, I can’t login to WP at site2, and the site2 website doesn’t display the front-page.php
.
Here are the steps I did so far:
-
Current local WP website is located here:
C:xampphtdocssite1localWP
(Note: DB name: localwp; user: wpxxxx; password:xxxxxxxxsite1, table prefix: wpsite1_) -
Create new folder here:
C:xampphtdocssite2localWP2
-
Copy all files from site1âs localWP folder to site2âs localWP2 folder
-
Go to
localhost/phpmyadmin/
, and click on Databases tab.
At top, type in new database name:localwp2
, and selectutf8_general_ci
for collation. Click on Create button. I got a success message, and now see the new DB listed (but no tables created yet). -
At top, click on Users tab. In middle of page, click on Add user link.
Type in user name: wpxxxx2. Click on Local for host (localhost). Type in password xxxxxxxxsite2 twice. Click all for Global privileges. Click on Go button. I got a success message, and now see the new user name listed. -
On side bar, click on the DB name for the original DB: localwp.
At top, click on Export tab. Click on Custom export method. Then click on Select All link under Tables. Under Output, click on Save output to a file radio button.
At the bottom, click on Go button. The backed up SQL file was saved to downloads. -
Now, on left side bar, click on the new DB name:
localwp2
.
At top, click on Import tab. Click on Browse button, and locate file I just exported, and click open. Go to bottom, and click on Go button. I got a message that 81 queries were executed. (same as what was on the localwp, so that is good!) -
Click on localwp2 on sidebar, and I can see all the tables. (But the table names are still prefixed with
wpsite1_
, where I wanted them to bewpsite2_
due to the export.) -
Now, go to
site2/localWP2
, and edit thewp-config.php
file. Change the follow lines of code from:define('DB_NAME', 'localwp'); define('DB_USER', 'wpxxxx'); define('DB_PASSWORD', 'xxxxxxxxsite1');
to:
define('DB_NAME', 'localwp2'); define('DB_USER', 'wpxxxx2'); define('DB_PASSWORD', 'xxxxxxxxsite2');
-
Go to new website location:
localhost/site2/localWP2
I get a site up, but the front-page.php is not displaying. It looks like it is serving theindex.php
page instead. -
Login into wp. Since I copied over the previously installed wp files, I have to use my original localwp user ID and password that I created when I did the initial install – right??. Which is dfxxxxx and xxxxxxxxxxx. But when I go to
localhost/site2/localWP2/wp-admin
, and try to login with the above userid, it immediately re-directs to this:http://localhost/site1/localWP/wp-login.php?redirect_to=http://localhost/site2/localWP2/wp-admin/&reauth=1
(and of course if I login, I am inside the site1/localWP, not the new site2/localWP2.)
Problems:
-
I think I am missing some step that will allow me login to wp on my site2. This might be resolved if I install the search & replace plugin and could search the
localwp2
database and replace: all references to localwp to localwp2; all references tolocalhost/site1/localWP
tolocalhost/site2/localWP2
and all references to WP Site 1 to WP Site 2. But since I can’t login to site2’s WP install I can’t do that. (I think if I try it, all I will be doing is changing my original install on my original DB.. not the new one.) -
Even though I can get to the home page of
localhost/site2/localWP2
(which is showing index.php instead offront-page.php
), I can’t tell if the rest of the site is OK, because as soon as I click on any other page, it immeditaly goes to the localhost/site1/localWP/… (whatever page)
Questions:
-
What do I need to do to fix my new site location to get the home page to show properly, and all the other pages displaying on site2.
-
What do I need to do to be able to login to WP for site2.
-
How can I get the tables of the new database localwp2 to have table prefixes of
wpsite2_
. At this point, is it too late to try changing mywp-config.php
to this:$table_prefix = 'wpsite2_';
(or should I not bother as it doesn’t really matter)?
(3a. NOTE: I just tried changing the table prefix and went to my site2 location, and it resolved to this: localhost/site2/localWP2/wp-admin/install.php
.. where it looks like it wants me to reinstall WP. So I just changed it back to the original prefix of wpsite1_
. Guess I answered my own questions.. that it can’t be changed in the wp-config.php
. I think would have to run some SQL against the database to change the table prefix there, and then change it in the config file.. so I think it is in the too hard basket, as long as it doesn’t really matter!) I would be curious for future installs how to get the table prefix changed (and at what point it should be done), if you have some resource you can point me to.)
Any suggestions for me would be greatly appreciated!!
You should redirect all URL of site1 to site2 in database of site2 .
Reference query :
Your login problem to site2 is due to the fact that the
siteurl
value in thewp_options
table is still set tosite1
url, which is causing the redirect. You can change thesiteurl
value directly to thesite2
url and you’ll be able to log in.I’d probably use a plugin like this: https://wordpress.org/plugins/wp-migrate-db/ and redo the export from site1, using the search and replace feature, and reimport it into the new site2 db.