Introduction
There are many ways to push changes you’ve made on one site to another. The most rudimentary way would be to download all files and the database as a backup, and then upload them to your production site. Luckily, we’ve made that quite simple with a one-time script, named sitecopy!
This assumes you know how to use SSH and terminal commands.
What sitecopy does
What sitecopy does is first fetch all files from your staging site and update your config file. After it, make a database dump and import it to your production site’s database. Remember that sitecopy does exactly what the name entails: it will make a copy of your staging site. This means that directories and files that don’t exist on stage but exist in production will be deleted. So be sure that staging corresponds to the setup of your production site. If you’re unsure, we recommend you make a backup beforehand.
Time needed: 15 minutes
- Log in to the production site with SSH.
Use PuTTY with Windows or the terminal for Mac and Linux. First, you need to log into the server via SSH:
ssh [PRODUCTION-USER]@[SERVER]
You’ll find the SSH login information under the Login Information on your site
- Get your SSH public key.
If you haven’t generated a SSH key pair before, you’ll have to run this command:
ssh-keygenand press enter three times until you’re through the setup. When generated, the key is saved by default as~/.ssh/ed_25519.pub. The next step is to copy that key somewhere so we can use it in step #4.
- Have your production site’s database credentials ready
If you have not written down or are unsure of your production site’s database credentials, then the simplest method is to check your config file. By default, it’s found in
~/site/public/wp-config.phpfor WordPress. Other CMS or setups will likely have another path and filename for their config file. An example of DB credentials found in thewp-config.phpfile:
- Save the public key on your staging site
Open a new terminal window and log into the staging site:
ssh [STAGE-USER]@[SERVER]. There you’ll need to paste the public SSH key into a new file calledauthorized_keysin the~/.sshfolder. When finished, you can exit out of this window, but keep the staging SSH login string in mind. To edit the file, run this command:nano ~/.ssh/authorized_keys - Run sitecopy from production.
Back in the terminal window for your production site, you can now run sitecopy. Ensure your staging site’s SSH login and production site’s DB credentials are ready. Under you’ll see how to format the command:
sitecopy [STAGE-USER]@[SERVER] [PRODUCTION-DATABASE] -p 'PRODUCTION-DB-PASSWORD'
Just hit enter, and the script will take care of the rest.
When the script finishes, you’re done!
And as always, should you have any questions or need any additional help you can contact our support chat at servebolt.com!