This happened again on one of my servers. The last time, it had to do with the lack of a swap file and then running out of physical memory. Usually a reboot helps which you do like this:
- Rebooting a Digital Ocean image by ssh into the machine and then
sudo service apache2 restart
and if that doesn’t work reboot the droplet withsudo shutdown now -r
- More in depth debugging. If you don’t mind having a server down or you were smart enough to have a load balancer so you can run two servers at once (yes, that’s on my list), you can check things like the amount of memory available. But you use
sudo netstat -plt
to see if mysql is running and restart withsudo service mysql star
t. If that works, then you can grep the log looking for low memoryzgrep -a "allocate memory" /var/log/mysql/error.log*
and you can see what is going on. You can also usefree -h
to see how much memory you really have. In our case, a 1GB machine had 151MB available. Which really isn’t very much. so a 2GB machine is probably better. - Swapfile for safety. If you are running out of memory, they don’t recommend using a swapfile because it degrades the SSD, so it’s better to just upgrade the droplet. Personally, I like the swapfile as a soft failure. But you can see if you have any with
sudo swap on --show
and if return nothing, then you don’t have it. The double check is to runfree -h
and see if Swap has anything. The do adf -h
to see if you have disk space. In our case, of our 25GB SSD, we were 80% free so no problem there. Then you allocate a swapfile that is equal to your memory, sosudo fallocate -l 1G /swapfile
, then make it read only and start itsudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo mkswap on
. Finally, if this workssudo free -h
should show it and make this permanent by adding a runningecho '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
to add a line to the table. - Resize Droplet. Of course, the better long term thing to do is to upgrade the droplet as WordPress in DigitalOcean really needs more that 1GB. For a website you use quite a bit, you probably want more like a $10/month site with 2GB and 50GB of SSD.