Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress From Bootstrap to WordPress Add Bootstrap Components to WordPress Theme From Bootstrap to WordPress Outro

Dawn Foster
Dawn Foster
1,899 Points

Copy local install of WP and theme from site1 folder to site 2 folder

Hi Zac:

Thanks for a great course.. it is was just what I needed at this point!! Especially to end up with a complete useable template to move forward with on future projects. Perfect!

I would like to make an exact duplicate of the WP setup & theme we just created in this course: all files, images, and database content.

Right now I have the WP install occurring in this location: C:\xampp\htdocs\site1\localWP. I want to make an exact copy of this install & theme, so I can make all the changes I want, and still have the original to fall back on if necessary.

Is there an easy way to do this? Copying DB and all? I am thinking I want to create the duplicate here: C:\xampp\htdocs\site2\localWP.

I want to have the starting point of this project, but then I will eventually want to change content, widgets, custom posts, etc.. - where basically it will become a completely different site. So I think I need a complete copy of the original WP install with current database content and theme files to start with, and not just create a new theme or child-them on the site1 install.

BTW: Where does the WP Database file actually reside??

I need to do this tomorrow, so any help will be appreciated.

Thanks, Dawn

4 Answers

Zac Gordon
STAFF
Zac Gordon
Treehouse Guest Teacher

Have you had a chance to watch out local dev course, I believe it shows at the end how to migrate a site to a live server. The process is the same for what you want to do except it's just a different folder and not a different server.

Zach Elkins
Zach Elkins
9,602 Points

If you want everything to be the exact same from the site 1, select your site 1 file and compress it to a zip file so you can have a copy always available and you won't have to worry about misplacing any of the files. You can then open the zip file and place the second instance of site 1 into your site 2 folder.

When you refer to the database file are you talking about the place where you actually assign the database information to in your wordpress file? If so, that is your wp_config.php file kept in the wordpress folder.

If you want to work with another, separate database for your second site you can setup a second database through MAMP's phpMyAdmin panel or XAMPP's equivalent. That way you can have better organization between site 1 and site 2

Dawn Foster
Dawn Foster
1,899 Points

Help!

I have tried to do as both you suggested to create a duplicate local copy of my treehouse bootstrap project.., but have run into a snag, and can't figure out what I did wrong.

After following all the steps to copy my site1 install to a 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:

  1. Current local WP website is located here: C:\xampp\htdocs\site1\localWP (Note: DB name: localwp; user: wpuser; password:xxxxxxxxsite1, table prefix: wpsite1_)

  2. Create new folder here: C:\xampp\htdocs\site2\localWP2

  3. Copy all files from site1’s localWP folder to site2’s localWP2 folder

  4. Go to localhost/phpmyadmin/, and click on Databases tab. At top, type in new database name: localwp2, and select utf8_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).

  5. At top, click on Users tab. In middle of page, click on Add user link. Type in user name: wpuser2. 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.

  6. 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.

  7. 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.

  8. 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 be wpsite2_ due to the export.)

  9. Now, go to site2/localWP2, and edit the wp-config.php file. Change the follow lines of code from:

        ```html
       define('DB_NAME', 'localwp');
       define('DB_USER', 'wpuser');
       define('DB_PASSWORD', 'xxxxxxxxsite1');
        ```
    

    to:

        ```html
       define('DB_NAME', 'localwp2');
       define('DB_USER', 'wpuser2');
       define('DB_PASSWORD', 'xxxxxxxxsite2');
        ```
    
  10. Go to new website location: localhost/site2/localWP2 I get a site up, but the front-page.php is not displaying as I am getting the “Oh no!” message, and a sidebar.. so it must be serving the index.php page instead.

  11. Login into wp. Since I copied over the previously installed wp files, I have to use my original localwp user ID and password (right??). Which is dfoster 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:

  1. 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 to localhost/site1/localWP to localhost/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.)

  2. Even though I can get to the home page of localhost/site2/localWP2 (which is showing index.php instead of front-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:

  1. 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.

  2. What do I need to do to be able to login to WP for site2.

  3. 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 my wp-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: http://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.

Zac Gordon and Zach Elkins .. do either of you have any suggestions for me... please!!

Dawn Foster
Dawn Foster
1,899 Points

I finally figured out the steps I was missing to fix the problems I outlined above. Note: The steps are customised to my setup. (These steps replace the last two steps above: 10 & 11!)

  1. Now that your database is all set up, you need to update the URLs inside your WordPress database referencing to your live site. You can do this by running an SQL query in phpMyAdmin. Make sure you have selected your new local site’s database (ie: localWP2) and then click on the SQL tab at the top. In phpMyAdmin’s SQL screen copy and paste this code below (after you have customised it for your site):

        ```SQL
       UPDATE wpsite1_options SET option_value = replace(option_value, 'http://localhost/site1/localWP', 'http://localhost/site2/localWP2') WHERE option_name = 'home' OR option_name = 'siteurl';
    
       UPDATE wpsite1_posts SET guid = replace(guid, 'http://localhost/site1/localWP','http://localhost/site2/localWP2');
    
       UPDATE wpsite1_posts SET post_content = replace(post_content, 'http://localhost/site1/localWP', 'http://localhost/site2/localWP2');
    
       UPDATE wpsite1_postmeta SET meta_value = replace(meta_value,'http://localhost/site1/localWP','http://localhost/site2/localWP2');
        ```
    
  2. Also had to go in and change the Blog (Site) Name from WP Site 1 to WP Site 2. It is located in the wpsite1_options table. From within phpMyAdmin, you can actually just edit the field directly, once you display the table.

  3. And the last step is to login to the admin section, navigate to your permalink structure (WP Admin menu: Settings/permalink) and hit "save". (Because you have to rebuild the permalink rules for the new server.) You don't even have to change them. Simply saving them rebuilds the data in your database.

And that's it!

Note: The reason I couldn't login to WP admin for site 2 was due to the Site name needing to be changed. Once I had done that, I think it would have been possible for me to go in and install the 'search & replace' plugin Zac suggests in his video.. which would take the place of the having to manually execute the SQL statements)

PS: I will probably go in and change my table prefix for the new DB. If you want to do that.. you might try this site for instructions: http://www.wpbeginner.com/wp-tutorials/how-to-change-the-wordpress-database-prefix-to-improve-security/