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 restartand if that doesn't work reboot the droplet with
sudo 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 -pltto see if mysql is running and restart with
sudo service mysql start. If that works, then you can grep the log looking for low memory
zgrep -a "allocate memory" /var/log/mysql/error.log*and you can see what is going on. You can also use
free -hto 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 --showand if return nothing, then you don't have it. The double check is to run
free -hand see if Swap has anything. The do a
df -hto 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, so
sudo fallocate -l 1G /swapfile, then make it read only and start it
sudo chmod 600 /swapfile && sudo mkswap /swapfile && sudo mkswap on. Finally, if this works
sudo free -hshould show it and make this permanent by adding a running
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabto 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.