OOM Killer Triggered by Excessive PHP-FPM Memory Usage on 2-Core 8GiB Ubuntu Server

Quick Steps to Resolve

1. Check Average Memory Used per PHP-FPM Process

Run:

ps --no-headers -o rss -C php-fpm8.2 | awk '{sum+=$1} END {print sum/NR/1024 " MiB per process"}'

➡️ Result: e.g., 96.81 MiB per process


2. Estimate Safe Memory for PHP-FPM

  • Total RAM: 8 GiB = 8192 MiB
  • Reserve for OS & Others: ~1.5 GiB
  • Available for PHP-FPM: 8192 - 1536 = 6656 MiB
  • Memory per PHP Process: ~90–100 MiB (rounded)

➡️ 6656 / 95 ≈ 70

Set pm.max_children = 70


3. Edit PHP-FPM Pool Config

Edit the file:

sudo nano /etc/php/8.2/fpm/pool.d/www.conf

Change/add these lines:

pm = dynamic
pm.max_children = 70
pm.start_servers = 8
pm.min_spare_servers = 4
pm.max_spare_servers = 12
pm.max_requests = 500

4. Reload PHP-FPM

sudo systemctl reload php8.2-fpm

This setup prevents your server from hitting memory limits and triggering the OOM killer while keeping PHP responsive under load.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top