NIce one, how about a function to create a staging copy from a production site?
This function is only for merging my modifications to the production site, right?
Hi,
pushing the files seems to work very well.
How about the database option? Maybe we can add some standard post scripts?
For example a database clone/copy script and than running a replace function for the host name?
The last might be done with WP-CLI
I tried some stuff in the mean time. This should work for a WordPress website:
mysql --user=username --password=passwd -e 'DROP DATABASE test_db;'
mysql --user=username --password=passwd -e 'CREATE DATABASE test_db;'
mysqldump --user=username --password=passwd live_db | mysql --user=username --password=passwd test_db
wp search-replace 'https://example.com' 'http://staging.example.com' --skip-columns=guid
What kind of code can I use insde the “Post Sync Script” field? Bash script?
It would be great if I could use some variables here.
Currently, when we sync the site, the staging environment copies the WordPress configuration from staging to production or vice versa.
This means that when performing a Prod-to-Staging sync, the staged WordPress site will connect to the production database.
If you need to run MySQL commands, you can run the commands with the following syntax:
mysql -uroot -e 'mysql command;'
You can provide Bash scripts in the Post Sync Script section, which will run after the sync is completed.
We recommend executing these scripts manually on the server first to verify that everything works as expected before using them as automated post-sync scripts.
Additionally, after some research, we found that the WP search-replace command can be run as follows:
Replace site_user with server user the site is associated with. Default is set to cleavr.
I hope this addresses your queries. If I have missed anything or misunderstood your requirements, please let me know, and I will follow up accordingly.
thanks for the examples and for mentioning the site and site_user variables.
I tried the WP cli command, but that one doesn’t work on URL’s in shortcodes (Elementor).
But it’s a beginning.
That’s not what you want, if you work on a staging site the database will be changed even after updating a plugin. You need a database copy. Using a mysql command without variables is like creating a staging site manually. Pushing a copy of your website to a new directory via SSH is not so much work, right?
A "One click “production to staging” function would be great (with a database copy of course)