I come from a Laravel background which means I am used to using database migrations and seedings to keep content on dev / staging sites in sync with my local environment.
I'm starting my first project in WordPress and was wondering how to go about doing the same. Essentially I'm building the site on my local environment and through the use of plugins such as Advanced Custom Fields I will create the content for the site. I need an easy was of ensuring the dev / staging sites have the same content as my local environment. I only want to sync content such as posts, pages, custom post types, and any associated media.
Deployment of code itself is not an issue as the code is kept under version control and I can create a webhook to auto deploy the code.
I have read up on plugins such as WP Migrate DB but I'm not sure this is the tool for the job.
Can anyone advise the best way to accomplish this?
That's the one main caveat of WordPress development, that even a seasoned WordPress developer still wonders what's the perfect automation for syncing database content from local environment to live server.
You can't just upload your database dump from your local development environment to the server and be happy with the results.
WordPress actually stores the resulting URLs in the database.
So let's say your local development URL is
http://localhost/awesome. Your posts as it stored in the database has also stored your development URL(i.e.
http://localhost/awesome) in every post. The URL is also stored in the
wp_options table. So when you import your local database dump to the server you need to replace the existing URL to the server URL in order for the post links to work.
To use the script, download the zip file from below, extract the folder called search-replace-db-master (assuming you are using the 3.1.0 version), renaming it to something secret of your choosing, upload it via FTP, SFTP or SCP to your web server’s public facing directory, then navigate to that folder in your browser. The script will automatically attempt to find and populate the database field but you must check that the details are correct and that it is for the database you wish to carry out a search/replace operation on.
A typical WP install with this script would have the folders as follows:
NOTE: Please read the Installation and Usage of the tool in their website, and make sure the details are correct upon proceeding with the replacement.
Live Server URL:
You provide the development URL to the
Replace Textbox and the live server URL to the
With Textbox. Make sure to have a backup of your database, then hit the button
dry run or
live run to perform the action.
Does it work all the time? Well, not so quick, it actually depends on your requirements, but so far in all my WordPress projects and its varying requirements it works as expected.
There's a lots of solutions out there and one of them is mentioned in your question(i.e. WP Migrate DB). You just got to bare the tedious workflow of WordPress development, as great as CMS WordPress has been throughout its existence there's still this one main caveat that lets us want to be freed.
WP Migrate DB is indeed the established pro tool.
There is also ServerPress' Desktop Server and Flywheel hosting's Local app (formerly Pressmatic). Both of these Windows and Mac apps generate a custom local development environment that can be shared on a network or over the network and pushed to staging or live sites on (some) hosts. The latter feature is not really mature in either app, especially the newer Local.
Finally there is VersionPress (currently Beta 4) -- a plugin and (in the works) a hosted service.
For our site, we've written a Perl script that copies the database then uses wp-cli commands to tweak certain settings that are local to a given site. The script also fires off a UNIX line command to sync up the uploads directories.
We use that when we need to copy the entire database, which gets plugin settings in addition to all content.
However, we also have a content staging site for our users, and we use RAMP to migrate individual content items (or batches of them) from the content staging site to the live site. This will bring all dependencies with a given post/page such as media attachments, taxonomy terms, users, etc. RAMP is geared toward the end user who is updating and creating content. It does require some customization to work with sites that have been customized using something like ACF.
Our typical workflow is to use RAMP to go between content staging and live, and then to use our copy script to refresh our dev and test sites with content at the content staging site.
Finally, since you're already using version control, you may wish to have a look at VersionPress which allows you to version the database. I've not used it but have been keeping an eye on development for a while and it's intriguing.