Solving WordPress Downtime: A Linux OOM Killer Case Study

Recently, I received a notification that one of the WordPress sites I set a while back was offline. That was weird because I set up two WordPress sites, both on Linode, using 2GB Ubuntu servers. Both of these servers were set up nearly identically except for different themes. I knew the unthinkable had happened, WordPress was murdered.

The server was still up, so I went in and ran sudo systemctl start apache2.

An hour or two later, I got another notification: it was down again.

I went back in and ran sudo systemctl start apache2 and it came back up. When I ran the start command it showed why it went down each time. The first time I figured it was a fluke, the second time I realized something was wrong.

As you probably guessed from the title of this article, the Linux OOM Killer stepped in and killed WordPress. I did some research on Stack Overflow and talked to ChatGPT about the issue.

At the same time, as I was trying to figure that out, I was having issues with Google Site Kit on that site. Due to my W3 Total Cache Google Site Kit could not inject its tags properly. So I disabled W3 Total Cache for a while.

The crashes stopped. A day later I re-enabled W3 Total Cache and set it to late loading for reasons. The crashes started back up.

Obviously, the theme I am using on that page is using up too much memory when the caching happens. I have plenty of storage on SSD, so I just created a 5GB swap file.

#Information Gathering
swapon -s
free -h
df -h

#Setting up the new swap file
sudo fallocate -l 5G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
swapon /swapfile
'/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

#Confirm it worked
free -h

Troubleshooting something like this can be frustrating, especially when you have multiple sites set up nearly identically. As soon as I realized the OOM Killer was the culprit, I knew I needed more RAM or a larger swap file. However, understanding the root cause of the crashes was crucial to me. Pinning it down to how my cache was operating brought me some relief. So it seems the case of how WordPress was murdered has been solved. It’s been a few days without any crashes, and I’m keeping my fingers crossed!