• Skip to secondary menu
  • Skip to main content
  • Skip to primary sidebar
  • Home
  • Projects
  • Products
  • Themes
  • Tools
  • Request for Quote

Vengala Vinay

Having 12+ Years of Experience in Software Development

  • Home
  • WordPress
  • PHP
    • Codeigniter
  • Django
  • Magento
  • Selenium
  • Server
Home » Why the Linux OOM Killer Terminates Your WordPress Processes on DigitalOcean (And How to Prevent It)

Why the Linux OOM Killer Terminates Your WordPress Processes on DigitalOcean (And How to Prevent It)

Understanding the Linux OOM Killer

The Out-Of-Memory (OOM) Killer is a crucial component of the Linux kernel designed to prevent a system from crashing entirely when it runs out of available memory. When the kernel detects that the system is critically low on RAM and swap space, it invokes the OOM Killer to reclaim memory. It does this by selecting one or more processes to terminate, based on a heuristic scoring system that aims to kill the “least important” or “most resource-hungry” process. For a WordPress site hosted on a DigitalOcean droplet, this often means your PHP-FPM workers, Apache/Nginx workers, or even the database process can be unceremoniously killed, leading to intermittent site unavailability.

Why WordPress is a Prime Target

WordPress, especially when running complex themes, numerous plugins, or handling high traffic, can be a significant memory consumer. Each PHP process (whether managed by Apache’s `mod_php`, PHP-FPM, or similar) needs memory to execute code, load libraries, and process requests. Database queries, caching mechanisms (like Redis or Memcached), and other background services further contribute to the overall memory footprint. When memory pressure mounts, the OOM Killer’s scoring algorithm might identify these WordPress-related processes as prime candidates for termination due to their potentially high memory usage or perceived low system importance compared to core kernel processes.

Identifying OOM Killer Activity

The first step in diagnosing OOM Killer events is to check the system logs. The kernel logs messages when it invokes the OOM Killer. On most Linux distributions, these messages can be found in:

  • /var/log/syslog
  • /var/log/messages
  • dmesg output

You can use grep to filter for relevant messages. Look for lines containing “Out of memory” or “killed process”.

Example Log Analysis

Run the following command to search your system logs for OOM killer events:

Checking `dmesg`

This command shows kernel ring buffer messages, which are often the most immediate source for OOM events.

Checking `syslog`

This command searches the system log file.

Checking `messages`

This command searches the older system messages file.

Tuning the OOM Killer: Adjusting `oom_score_adj`

The OOM Killer uses a score to determine which process to kill. This score is influenced by several factors, including the process’s memory usage and a tunable parameter called oom_score_adj. This value ranges from -1000 (never kill) to +1000 (always kill). By default, most processes have an oom_score_adj of 0. You can adjust this value for specific processes to make them less or more likely to be killed.

Making Processes Less Likely to be Killed

To make a process less likely to be killed, you need to assign it a negative oom_score_adj. A value of -1000 will effectively disable the OOM Killer for that process, but this is generally not recommended as it could lead to system instability if that process consumes all memory. A more reasonable approach is to assign a moderately negative value.

Example: Protecting PHP-FPM Workers

If your PHP-FPM workers are being killed, you can adjust their oom_score_adj. First, you need to identify the Process ID (PID) of your PHP-FPM master process or worker pool. You can often find this using ps or pgrep.

Finding the PHP-FPM PID

Assuming your PHP-FPM pool is named ‘www’, you might use:

Setting `oom_score_adj`

Once you have the PID (e.g., 12345), you can set its oom_score_adj. For example, to make it less likely to be killed, set it to -500:

Making `oom_score_adj` Persistent

The above method is temporary and will be reset on reboot or when the process restarts. To make it persistent, you can use systemd service files or a startup script. For systemd, you can modify the PHP-FPM service file.

Systemd Service Modification (Example for PHP-FPM)

Locate the PHP-FPM service file (e.g., /etc/systemd/system/php7.4-fpm.service or similar). You can override settings using a drop-in file.

Create a drop-in configuration file:
Add the following content to /etc/systemd/system/php7.4-fpm.service.d/oom.conf:
Reload systemd and restart PHP-FPM:

Increasing System Memory

While tuning the OOM Killer can help prevent specific processes from being killed, it doesn’t solve the underlying problem of insufficient memory. The most robust solution is to increase the available memory for your droplet.

Monitoring Memory Usage

Before scaling up, it’s crucial to understand your current memory usage. Tools like htop, atop, and vmstat are invaluable.

Using `htop`

htop provides a real-time, interactive view of running processes and system resource usage. It’s often more user-friendly than top.

Using `atop`

atop is excellent for historical analysis as it logs system activity. You can review past memory usage to identify trends and peak consumption times.

Using `vmstat`

vmstat reports virtual memory statistics.

Scaling Your DigitalOcean Droplet

DigitalOcean offers various droplet sizes. If your monitoring indicates consistent high memory usage, consider upgrading to a droplet with more RAM. This is often the most straightforward and effective solution for preventing OOM killer events caused by genuine memory exhaustion.

Configuring Swap Space

Swap space acts as an extension of your RAM, using disk space to store data that isn’t actively being used. While slower than RAM, it can prevent the OOM Killer from activating prematurely. DigitalOcean droplets often come with minimal or no swap configured by default.

Checking for Existing Swap

Use the following command to see if swap is already active:

Creating a Swap File

If no swap is found, you can create a swap file. A common recommendation is to create a swap file equal to the amount of RAM, or up to 4GB if RAM is very large.

Step 1: Create an empty file for swap

This command creates a 2GB file named swapfile. Adjust 2G as needed (e.g., 4G).

Step 2: Set correct permissions

Only the root user should be able to read and write to the swap file.

Step 3: Set up the Linux swap area

Step 4: Enable the swap file

Step 5: Make the swap file permanent

Add an entry to /etc/fstab so the swap file is mounted on boot.

Step 6: Adjust swappiness (Optional but Recommended)

The swappiness parameter controls how aggressively the kernel swaps memory pages. A value of 60 (default) means the kernel will swap pages when it’s moderately busy. For servers, especially those with sufficient RAM, a lower value (e.g., 10) can be beneficial, prioritizing keeping data in RAM.

Check current swappiness:
Set swappiness temporarily:
Make swappiness permanent:

Add the following line to /etc/sysctl.conf:

Conclusion

The Linux OOM Killer is a safety net, but its activation on a WordPress server indicates an underlying resource constraint. By understanding how the OOM Killer operates, monitoring your system’s memory usage, and implementing strategies like adjusting oom_score_adj, increasing droplet resources, and configuring swap space, you can significantly improve the resilience and stability of your WordPress deployments on DigitalOcean.

Primary Sidebar

A little about the Author

Having 12+ Years of Experience in Software Development, Vinay is a principal software architect, senior systems engineer, and elite technical consultant. He specializes in bespoke PHP/WordPress development, high-performance Magento 2 & Shopify architectures, custom plugin/theme development from scratch, and legacy code modernization (including VB6, VB.NET, PyQt, and Crystal Reports). Known for solving complex database bottlenecks, speed optimization (Core Web Vitals), and advanced security code auditing, Vinay engineers production-ready systems designed to scale under heavy concurrent load conditions.



Chat on WhatsApp

Recent Posts

  • Top 100 Developer Tooling and Productivity SaaS Ideas to Launch in 2026 to Boost Organic Search Growth by 200%
  • Top 100 Developer-Centric Code Snippet Managers and Customization Plugins to Double User Engagement and Session Duration
  • Top 5 API Monetization Frameworks and Gateway Strategies for Developers to Minimize Server Costs and Load Overhead
  • Top 50 Automated PDF & Document Generation Tool Ideas for Developers to Minimize Server Costs and Load Overhead
  • Top 50 Premium Newsletter and Subscription Business Models for Devs for High-Traffic Technical Portals

Categories

  • apache (1)
  • Business & Monetization (386)
  • Centos (4)
  • Comparisons & Decision Making (55)
  • Debian (2)
  • Debugging & Troubleshooting (536)
  • DevOps (7)
  • DevOps & Cloud Scaling (937)
  • Django (1)
  • Migration & Architecture (124)
  • MySQL (1)
  • Performance & Optimization (694)
  • PHP (5)
  • Plugins & Themes (166)
  • Security & Compliance (530)
  • SEO & Growth (465)
  • Server (23)
  • Ubuntu (9)
  • WordPress (22)
  • WordPress Plugin Development (7)
  • WordPress Theme Development (165)

Recent Posts

  • Top 100 Developer Tooling and Productivity SaaS Ideas to Launch in 2026 to Boost Organic Search Growth by 200%
  • Top 100 Developer-Centric Code Snippet Managers and Customization Plugins to Double User Engagement and Session Duration
  • Top 5 API Monetization Frameworks and Gateway Strategies for Developers to Minimize Server Costs and Load Overhead
  • Top 50 Automated PDF & Document Generation Tool Ideas for Developers to Minimize Server Costs and Load Overhead
  • Top 50 Premium Newsletter and Subscription Business Models for Devs for High-Traffic Technical Portals
  • Top 100 SEO and Schema Markup Plugins for Headless Decoupled Sites for Independent Web Developers and Indie Hackers

Top Categories

  • DevOps & Cloud Scaling (937)
  • Performance & Optimization (694)
  • Debugging & Troubleshooting (536)
  • Security & Compliance (530)
  • SEO & Growth (465)
  • Business & Monetization (386)

Our Products

  • School Management & Student Administration System
  • Integrated Hospital & Clinic Management System
  • Real Estate Directory & Agent Portal
  • Restaurant POS & Table Booking System
  • Retail Inventory POS & Billing System
  • Pharmacy Inventory & Clinic Billing System

Our Services

  • Vibe Engineering & AI Code Auditing Services
  • Prompt Engineering & "Vibe Coding" Workflow Consulting
  • AI-Augmented "Vibe Coding" & Rapid MVP Development
  • Figma to Shopify Liquid Theme Customization
  • Figma to WooCommerce Frontend Development
  • Figma to Magento 2 Theme Development

Copyright © 2026 · Vinay Vengala