Cloning a site from Live to Local with Vagrant and VVV
A common need for WordPress site development requires pulling a client site from a live host in order to work on it locally. There are various methods of doing this, some faster, and others with a slighter learning curve, but I’ve determined this approach to be fast enough and it allows me to have the benefits of a Vagrant setup. The use-case for this is most likely to be a pre-existing site.
Assuming you have Vagrant and VVV installed (and if you don’t have a look here), a local WordPress development site can easily be set up with Vagrant and Variable VVV - a VVV Site Creation Wizard
Use the site wizard https://github.com/bradp/vv by following the instructions to install
Get a backup of the live WordPress database and find its path
pwd
to use in the next stepCreate a new VVV site
go to vagrant folder
vagrant up
vv create
You will see the following prompts:
Name of new site directory: myclonedsite
Domain to use (leave blank for myclonedsite.dev):
WordPress version to install (leave blank for latest version):
Install as multisite? (y/N):
Git repo to clone as wp-content (leave blank to skip):
Local SQL file to import for database (leave blank to skip): myclonedsite.sql
Remove default themes and plugins? (y/N):
Add sample content to site (y/N):
Enable WP_DEBUG and WP_DEBUG_LOG (y/N):
- Test the site locally. A link and access information will be provided in the prompt.
Cloning a Git Repository as wp-content
This can dramatically speed things up and allow you to pull the whole site down in one go. Unfortunately, I don’t agree with the idea of versioning the whole wp-content folder so in that case it creates an extra step for me. So if you do this anyway or don’t mind the extra step you can simply add the url of the Git repo after this prompt.
Using WP-CLI to add content
Very often you will not want the same content as appears on the live site. Perhaps you are
SSH into your vagrant server
vagrant ssh
go to the site itself
cd /srv/www/myclonedsite
use WP-CLI commands to add themes and content