Laravel FPM Crashes on Native PHP 8.2: Why Your Queue Workers Keep Hitting “Process Never Restarts” & How to Fix It in 5 Minutes on cPanel VPS with Redis and Ocache 🚀
You’re staring at a flooded log, the queue workers are looping, and the FPM master process refuses to respawn. It feels like the server is sabotaging your production release. You’re not alone—every Laravel engineer hitting PHP 8.2 on a stock cPanel VPS has hit this wall.
Why This Matters
When PHP‑FPM dies, every HTTP request and every queued job is forced to wait for a new worker to spin up. In a live SaaS environment that translates to lost API speed, higher latency for WordPress + Laravel hybrids, and a spike in error‑rate alerts. The longer the downtime, the more revenue you lose and the harder it is to keep your MySQL and Redis caches warm.
Common Causes
- Native PHP 8.2 compiled without
--enable-fpmflags on the cPanel build. - Incompatible
php-fpm.confvalues (e.g.,pm.max_childrenset too high for the VPS RAM). - Supervisor trying to restart a worker that never exits because the PHP binary crashes.
- Redis connection timeout caused by the default
tcp_keepalive_timeon the VPS. - Ocache (OPcache) memory limits that cause “process never restarts” errors when the opcode cache is full.
/var/log/php-fpm/error.log often reads “[pool www] child 12345 said into stderr: PHP Fatal error: Allowed memory size of … exhausted” followed by the dreaded “process never restarts” line.
Step‑By‑Step Fix Tutorial
1. Verify PHP‑FPM Version & Build
php -v
php-fpm8.2 -v
If the output shows “cPanel” in the build string, you’re on the stock binary that lacks the required --enable-fpm flag for PHP 8.2.
2. Install a Custom PHP 8.2 with FPM Support
yum install -y epel-release
yum install -y https://repo.remi.com/enterprise/remi-release-8.rpm
yum module reset php
yum module enable php:remi-8.2
yum install -y php php-fpm php-cli php-redis php-opcache
Make sure the php-fpm service is enabled and started:
systemctl enable php-fpm
systemctl start php-fpm
3. Tune php‑fpm.conf for a 2 GB VPS
[www]
user = nobody
group = nobody
listen = /var/run/php-fpm.sock
listen.owner = nobody
listen.group = nobody
pm = dynamic
pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
php_value[session.save_handler] = redis
php_value[session.save_path] = "tcp://127.0.0.1:6379"
Adjust pm.max_children so that max_children * php_memory_limit stays under 75 % of your total RAM.
4. Re‑configure OPcache (Ocache) Limits
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.validate_timestamps=1
opcache.revalidate_freq=2
Place these directives in /etc/php.d/10-opcache.ini and reload FPM:
systemctl reload php-fpm
tail -f /var/log/php-fpm/error.log should show no more “process never restarts” messages.
5. Update Supervisor Config for Laravel Queue Workers
[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /home/username/laravel/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=webuser
numprocs=4
redirect_stderr=true
stdout_logfile=/home/username/logs/laravel-queue.log
stopwaitsecs=3600
After editing, run:
supervisorctl reread
supervisorctl update
supervisorctl status laravel-queue*
VPS or Shared Hosting Optimization Tips
- Swap management: Disable swap on a low‑memory VPS to force processes to respect memory limits.
- cPanel “Select PHP Version”: Point it to the custom binary in
/opt/remi/php82/root/usr/bin/php. - Apache + mod_proxy_fcgi: If you can’t switch to Nginx, add a
ProxyPassMatchblock that points to the Unix socket. - Enable Cloudflare “Automatic HTTPS Rewrites” to offload TLS termination and reduce CPU load.
- Use MySQL 8.0 with innodb_buffer_pool_size ≈ 50 % of RAM.
composer update via SSH, but keep the --no-dev flag to avoid pulling unnecessary packages that bloat memory.
Real World Production Example
Acme SaaS runs a Laravel API gateway behind Nginx on a 4 GB Ubuntu 22.04 VPS. Before the fix:
- Queue latency: 45 seconds
- CPU spikes: 95 % during peak traffic
- FPM restarts: every 7 minutes, causing 502 errors
After applying the five‑minute FPM tune and OPcache bump, the same metrics dropped to:
- Queue latency: 2‑3 seconds
- CPU average: 28 %
- No unexpected FPM restarts for 30 days
Before vs After Results (Graphic‑Free)
Metric | Before | After
---------------------------------------------------------------
PHP‑FPM crashes | 8/hr | 0/hr
Queue worker lag | 45s | 2.8s
CPU usage (peak) | 95% | 28%
Memory pressure | OOM kills | Stable
Security Considerations
- Lock down
php-fpm.sockpermissions (600) and setlisten.owner/listen.groupto the web user. - Enable
disable_functionsforexec, shell_exec, systeminphp.iniunless required for deployment scripts. - Use
chrootin Supervisor (or systemd) to isolate queue workers from the rest of the file system. - Keep Redis password‑protected and bind only to
127.0.0.1. - Regularly audit Composer dependencies with
composer audit.
Bonus Performance Tips
- Enable
fastcgi_cachein Nginx for static Laravel responses. - Set
redis.maxmemory-policy allkeys-lruto keep the most frequently accessed API tokens hot. - Run
php artisan config:cacheandphp artisan route:cacheafter every deploy. - Leverage Laravel Horizon to monitor queue health in real time.
- Consider a lightweight Docker sidecar for PHP‑FPM on a VPS that supports containerization; it isolates libraries and prevents host‑level PHP upgrades from breaking your app.
FAQ
Q: My cPanel still shows “PHP 8.2 (native)” even after installing Remi’s package. Why?
A: cPanel caches the binary path. Go to WHM → MultiPHP Manager**, select the domain, and point it to /opt/remi/php82/root/usr/bin/php. Then rebuild the Apache profile.
Q: Do I need to restart Apache after changing the FPM socket?
Yes. Run systemctl reload httpd (Apache) or systemctl reload nginx to pick up the new socket path.
Q: My Redis latency spikes during backup windows. Is this related?
Often. Disable Redis persistence (save "") during snapshots or move backups to a replica.
Q: Can I use the same fix on a shared hosting environment?
Partially. You can only control .user.ini for OPcache and use php artisan queue:work --daemon without Supervisor, but the root cause is usually the provider’s PHP‑FPM build.
Final Thoughts
PHP 8.2 brought many performance improvements, but the out‑of‑the‑box cPanel build still lags behind a true production‑grade FPM setup. By swapping the binary, tightening php-fpm.conf, and giving OPcache the breathing room it needs, you can eliminate “process never restarts” errors in under five minutes. The payoff is immediate: faster API responses, healthier queue workers, and a more stable WordPress‑Laravel hybrid on the same VPS.
Take the steps, monitor the logs, and you’ll have a rock‑solid backend that scales without a hitch. If you need a reliable yet inexpensive VPS to test these changes, check out cheap secure hosting at Hostinger – the same environment many devs use for their production Laravel‑WordPress stacks.
Monetization Angle (Optional)
Ready to package this knowledge into a service? Offer a Laravel + WordPress health‑check for $199/month: daily FPM tuning, Redis health monitoring, and automatic Supervisor restarts. Use the same script you just built and sell it as a managed add‑on for agencies that run hybrid sites on cPanel VPS.
No comments:
Post a Comment