phpcrashcpanelwhmalmalinux

PHP goes down randomly on a WHM server under AlmaLinux 8.10 and PHP 8.4.2. What can it be?


I have servers accessible through WHM and CPanel (I don't know if it's relevant). They run on AlmaLinux 8.10 and PHP 8.4.2.

On one of my servers, randomly, every single web site stop working (they stop responding as if the sites were down) and I have to restart the "PHP-FPM service for Apache" to make everything work again.

There are about 60 websites on the server, ±15% free disk space. The vast majority are Wordpress (some with wooCommerce) sites with moderate trafic. The others are pure PHP sites. I don't see specific spikes in trafic, cpu or disk usage. Has it ever happened to anyone here? What could it be? We inspected all we could think of, but found nothing that solves the problem.

Here's what my tech is sending me (in case it's relevant) : Server Version: Apache/2.4.62 (cPanel) OpenSSL/1.1.1k mod_bwlimited/1.4Server MPM: preforkServer Built: Dec 16 2024 19:38:04

Thanks


Solution

  • Finally, we have not had a crash since I made the request for logs to our tech because we tried a new fix just prior and it seems to have worked (no crash since).

    Here is the link to what solved our problem (the first solution): https://www.cogmentis.com/php-fpm-crashing-on-cpanel-server-fixed/

    Here is what it says: On a cPanel server, all pools for a particular version of PHP share the same master process (owned by root), and therefore share the same pool of memory allocated for Opcache.

    The actual pools themselves are, however, owned by the user account they serve.

    When Opcache reaches its forced restart time, it issues a kill_all_lockers() command.

    Opcache then tries to force quit (kill) all the PHP-FPM processes holding locks so it can restart, but because the FPM pools are owned by specific users, it doesn’t have permission… which freaks the server out and causes the crash.

    However, the advice to add kill_all_lockers to disable functions just didn’t seem to work for me, and disabling/removing Opcache seemed like a backwards step.

    (And no, restarting PHP-FPM every few minutes really didn’t seem like a good option either).

    So what’s the solution?

    Simple really… stop Opcache issuing a kill_all_lockers() command!

    Looking at the code for the Opcache ZendAccelerator, we can see kill_all_lockers() is invoked on line 922 if (and only if) the opcache.force_restart_timeout is enabled.

    So by setting opcache.force_restart_timeout=0 in our PHP ini settings, Opcache will never try to force a restart using kill_all_lockers(), and will never crash.

    To do this, simply edit the INI settings of each PHP version using the WHM MultiPHP INI Editor and add an opcache section at the end as follows:

    [opcache]
    ; Disable restarting long-running scripts, as this does not work with cPanels implementation
    ; Enabling can cause PHP-FPM to crash with 100% CPU due to kill_all_lockers bug
    ; cPanel Default: 180
    opcache.force_restart_timeout = 0
    

    Thanks to all for your help.