user4815703
user4815703

Reputation:

Procedure to Copy Production Wordpress to Vagrant?

i have just began on working with vagrant. I have this clients ssh and db info.

I would like to know what files do i need to copy using ssh or ftp to my vagrant box? To be able to completely replicate the target wordpress server.

Is is as simple as copying entire wordpress related folders and editing wp-config for database as well as importing the database?

Thanks

Upvotes: 0

Views: 311

Answers (1)

Frederic Henri
Frederic Henri

Reputation: 53713

As pointing from the link in my comment and using the suggested tool on VVV, they suggest the following procedure

Using this tool you can easily create a clone of an existing live site. Here are some steps to make that happen.

  1. On your live site, do a database dump. This could be done a number of ways, ranging from using a custom admin panel from your host, to phpMyAdmin, to good old raw command line. Make sure to use the flag to include the DROP TABLE commands. Take the sql file you just made and put it in your vagrant docroot. If you followed the VVV instructions exactly that would be vagrant-local/www/
  2. Copy all the file assets custom to your site to your local environment. This would probably be everything in wp-content, and it would all go inside the wp-content folder for your local site.
  3. Third, we do some WordPress magic. We're going to SSH into your vagrant install and use WP-CLI to import the database dump from your live site. If you're using windows then you'll need an SSH client like PuTTY. Otherwise, pull up a terminal window and go into your vagrant-local directory. Then type vagrant ssh and press enter. In a second or so you'll be ssh'd into your local server.

From there you need to get to your docroot. This is done with:

cd /srv/www/

To check to make sure your SQL file is there you can simply do:

ls

and it should list everything in there. Once you see your SQL file you can type:

wp db import my_sql_file.sql

where my_sql_file.sql gets replaced by the real name of your file. This will import your database file from your live site.

IMPORTANT: at this point your local site will be broken, because it thinks that it is your live site, since your live site URLs are in the database. We can fix that with a quick search and replace.

While still in your SSH connection, you need to cd into the root of your new site. Your previous ls should have shown you the directory for that site, simply cd into it.

Once you're in there, do this:

wp search-replace olddomainname newdomainname --dry-run

where olddomainname would be the domain name of your live site, and newdomainname would be the domain name of your local dev site. The --dry-run means it won't actually do anything, merely tell you what it WOULD have done.

If the results look good, run it again without the --dry-run.

At that point you should be able to go to your local domain name for your site in your browser and see a local copy of your live site.

Upvotes: 1

Related Questions