Fixing WordPress crashes on DigitalOcean Droplet

OK I get this about three weeks or so on our new DigitalOcean Droplet running WordPress. The good news is the JetPack does inform you when it dies.

TL;dr

If you have your WordPress created with the one-click Droplet under DigitalOcean it works great except that there is no swapfile, so with a 1GB RAM server that $5 buys you, you can have Mysql run out of memory. The longer term solution is to upsize the RAM, but this is a case where you really do want a Swapfile. Even with a 25GB SD, having a 2GB swapfile should solve lots of problems and it is four lines to add.

The details

On Bluehost, this basically has never happened. A restart of the droplet seems to help, but it would be good to figure out what is going on.

This is a very common problem and WP Beginner has a diagnostic set.

  1. See if your host is up. A quick ssh can check to make sure the Droplet is still running.
  2. Does the problem occur with the administrative interface /wp-admin/. If it says the database needs to be repaired, then you can add definte('WP_ALLOW_REPAIR', true to wp-config.php and you can fix it and then go to http://yoursite.com/wp-admin/maint/repair.php
  3. Check your WP-Config.php file and if you didn’t change your database password (why would you?), then you make need to change the DB_Host from localhost to define('DB_HOST', '127.0.0.1:8889 but this didn’t work either. Or try 3306
  4. See if MySQL Server is up and running. You need a sample application that tests this.

<?php$link= mysqli_connect('localhost', 'username', 'password');if(!$link) {die('Could not connect: '. mysqli_error());}echo'Connected successfully';mysqli_close($link);?> If this ends with could not connect then MySQL is down for some reason. 

How to debug Mysql

OK, so that wasn’t of much help, time to figure out what to do when Mysql is unavailable. DigitalOcean has a good tutorial on this:

  1. Look at the error log, they are kept in var/log/mysql/error.log and it was pretty revealing, the last line was /usr/sbin/mysqld: Shutdown complete
  2. Looking up it says, Failed to initialize builtin plugins and then it shows that InnoDB failed because it could not allocate buffer memory.

So I”m wondering if my 1GB tiny WordPress Droplet is too small and StackOverflow confirms that it will not run in a $5/month droplet because of memory shortages. You need more RAM and you should allocate a Block Volume.

Restarting Mysql

To test this, you can just restart Mysql with service mysql restart and see if it works It won’t tell you what is really wrong, but will get you going again.

No Swapfile for WordPress Droplet installations

Ok, part of the problem seems to be that there is no swapfile for the DigitalOcean droplet. That is swapon -s reveals nothing and there is no /swapfile

If you already have a swapfile, here is how to increase the size, first turn off the swap and then first disable the swapfile and delete. See https://askubuntu.com/questions/1075505/how-do-i-increase-swapfile-in-ubuntu-18-04

sudo swapoff /swapfile
sudo rm  /swapfile

The other thing it could be is that Apache is overloading because of too much access to XMLRPC, but that doesn’t seem like the problem. With Ubuntu 18.04, a swapfile can be just about anything, but by convention, /swapfile is used, so to create one, it looks like to create a 2GB swapfile

dd if=/dev/zero of=/swapfile count=2K bs=1M
mkswap /swapfile
sudo chown root:root /swapfile
sudo chmod 600 /swapfile
sudo swapon /swapfile

I’m Rich & Co.

Welcome to Tongfamily, our cozy corner of the internet dedicated to all things technology and interesting. Here, we invite you to join us on a journey of tips, tricks, and traps. Let’s get geeky!

Let’s connect

Recent posts

Loading Mastodon feed…