Optimize PHP-FPM

Peter Knowles
2 min readApr 20, 2024

If you deploy servers with LAMP or LEMP stacks that are going to host a large volume of PHP applications, using PHP-FPM (Fast CGI Manager) you may quickly realize the default settings may cause your site to go into overdrive, using lots of RAM and not really giving it back in a reasonable time, causing your system to quickly become instable.

So, just upgrade the RAM you say? Sure that might solve the problem temporarily, but the likelihood is you’ll start to experience the issue again and again while not actually addressing the cause.

After some research, and working through a recent installation that was “eating” RAM up rapidly, I came across a few adjustments that you can make to your PHP-FPM configuration which will surely bring this nightmare to a halt.

Reducing Memory Usage

Depending on your operating system, and/or distribution, the following files may exist elsewhere or be named differently. However, for demonstration purposes, we’ll outline the typical location for Ubuntu 20.04 LTS.

The default configuration pool is www and located at: /etc/php/{version}/fpm/pool.d/www.conf

*** replace “version” above with the PHP version installed ***

Inside the above configuration, find and adjust the following directives to:

  • pm = ondemand
  • pm.max_children = 80
  • pm.process_idle_timeout = 10s
  • pm.max_requests = 200

--

--