I’ve been hosting my WordPress sites with Digital Ocean for a few months now. It took me quite a while to learn how to manage everything, and I thought it would be worth sharing a few shortcuts and tricks I’ve picked up.
If you’re looking to migrate your sites to Digital Ocean, I also have a post on that.
The way to get on the server is to SSH:
However, no one wants to memorize an IP address or type that much. If you’re logging in a lot, set up an SSH alias.
Host example HostName 127.0.0.1 User user
Now, you just need to type “ssh example” to get to your server.
Download Files from the Server
If you need to download a directory from the server, you can do that with scp:
scp -r [email protected]:/var/www/mysite.io/htdocs/wp-content/ .
This pulls the entire “wp-content” folder from your remote site into your current path on your local machine.
Reverse it to go the other way:
scp -r wp-content [email protected]:/var/www/mysite.io/htdocs/
Syncing WordPress Files
If you’re developing locally, you probably need to occasionally sync files. Rsync is a great way to do that because it only downloads/uploads the files that have changed.
You can also exclude files you don’t want to sync, like a cache directory. Here’s one command I use all the time to pull down updates:
rsync -rvz --exclude "w3-total-cache" --progress [email protected]:/var/www/mysite.io/htdocs/wp-content/ /Users/Me/Sites/mysite/'
This syncs any changes in the “wp-content” folder on the remote server to the “wp-content” directory in “mysite” locally.
You can reverse the paths to go the other way (be careful!), and of course, set up an alias or shell script if you need to do this a lot.
Updating the Server
It seems like every time I log into the server there’s updates. Here’s how you get those:
sudo apt-get update # Fetches the list of available updates sudo apt-get upgrade # Strictly upgrades the current packages sudo apt-get dist-upgrade # Installs updates (new ones)
MySQL seems to conk out every now and then on Digital Ocean. Enabling Swap really helped with that. But sometimes you just need to:
Cron Job to Restart MySQL
If MySQL conks out on a regular basis because of memory errors, it might be a good idea to upgrade the droplet. In my case, MySQL failed about every 3-4 weeks and overall CPU use was still low. So I just decided to set up a cron job instead. This runs every minute and will restart MySQL if it is down.
To set it up, log in and type:
sudo crontab -e
Then add this line to the bottom of your crontab:
* * * * * /etc/init.d/mysql start
For a more detailed account of how cron jobs work (or to set different times), read this.
I am new cron jobs, so if anyone has improvements/alternates to this approach I’d love to know it.
service nginx reload
Hope some of these tips are useful! Feel free to share your own.