Wordpress & WooCommerce: Localhost, Staging and production environments and how to sync them without losing data

I'm working on my first WooCommerce site for an e-commerce shop I'll be launching hopefully in January (I should say that I've been working with Wordpress since the very beginning, so I'm not new to WP or PHP development) but I'm struggling with how to setup a good development/production environment.

I've been searching for an answer to this but so far the closets I've come to an answer was that there is no "good way" to do it and require manually updating.

The problem is of cause that Wordpress keeps everything in the same database, from posts (and orders) to settings and meta-data.

Previously I've been able to make an duplicate or snapshot of my production site, overwrite my localhost, and then work from there. Confidence that my production site will not receive any new content in the meantime.
But this is not very likely for an ecommerce website.

The files itself is not the issue, this is handled by git but the database is a much more difficult nut to crack.

I'm the developer. We have an designer / CSS wizard too, and we both work on localhost. Then, we have a storage guy and a sells guy and for them to approve and preview changes, we have an online staging environment. And as the very last thing we, of cause, have the production environment, the actually "store".

I would appreciate any thoughts, ideas, links or other great advice in how others have solved this or if there is some nice structures / plugins that can help in ensure that this can be done properly.

Thanks

Topic woocommerce-offtopic localhost sync staging production Wordpress

Category Web


Try VersionPress. It brings Git operate (pull/push) into WordPress. Except for diff from files, VersionPress also do diff to database.

With VersionPress, you can merge staging to production, and resolve conflicts.


I recommend to work with fixtures on localhost and development environments.

Fixtures definition from Symfony documentation:

Fixtures are used to load a "fake" set of data into a database that can then be used for testing or to help give you some interesting data while you're developing your application.

To work with fixtures on WordPress you can use wp-cli and wp import command to import WXR files. Of course you can keep WXR files in repository to provide data for other developers. Using fixtures you are providing consistent data to all developers and testing environment.

For staging environment I would recommend to replicate production database.

I don't know if you plan to update database schema as your app will grow. WordPress is so elastic that in my 95% cases I don't need to update schema. If you think you have such a case get familiar with database migrations. Basically migrations are scripts which know if database schema need to be updated, will update it and optionally can do rollback if something goes wrong during deploy.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.