Friday, May 8, 2026

Fixing the “Laravel Queue Worker Doesn’t Start on cPanel VPS – My PHP‑FPM & Cron Crashes” Mystery That’s Slowing Your Site to a Crawl Speed in Production 😂🚀

Fixing the “Laravel Queue Worker Doesn’t Start on cPanel VPS – My PHP‑FPM & Cron Crashes” Mystery That’s Slowing Your Site to a Crawl Speed in Production 😂🚀

You’ve just deployed a Laravel‑powered API behind a WordPress front‑end, and the queue worker refuses to spin up on your cPanel VPS. Cron emails you “PHP‑FPM SIGSEGV”, the CPU spikes, and your site crawls at a snail’s pace. Sound familiar? You’re not alone. Developers across the United States spend hours chasing log noise only to discover a single mis‑configured supervisor file is holding the entire stack hostage.

Why This Matters

Queue workers are the heartbeat of any modern Laravel app—email notifications, webhook retries, image processing, you name it. When they stall:

  • Customer‑facing APIs time out.
  • WordPress plugins that rely on background jobs (e.g., SEO crawlers) become useless.
  • Server resources balloon, causing other tenants on the VPS to suffer.

In production, every millisecond of delay translates to lost revenue and lower search rankings.

Common Causes

  1. Supervisor mis‑configuration. Wrong user/group, missing environment file, or an incorrect numprocs value.
  2. PHP‑FPM pool limits. Low pm.max_children or pm.max_requests cause worker crashes when the queue spikes.
  3. Cron daemon conflicts. Running php artisan queue:work both via cron and Supervisor leads to double‑forking.
  4. Redis connection timeout. Unoptimized redis.conf on a low‑memory VPS.
  5. Composer autoload cache. Out‑of‑date vendor folder after a server upgrade.

Step‑by‑Step Fix Tutorial

INFO: All commands assume you are logged in as root or have sudo privileges on an Ubuntu 22.04 VPS running cPanel.

1. Verify PHP‑FPM Pool Settings

# /etc/php/8.2/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 30
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
request_terminate_timeout = 300

After editing, reload PHP‑FPM:

systemctl reload php8.2-fpm

2. Clean Up Supervisor Config

# /etc/supervisord.d/laravel-queue.conf
[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /home/username/laravel/artisan queue:work redis --sleep=3 --tries=3 --daemon
autostart=true
autorestart=true
user=cpanelusername
numprocs=2
redirect_stderr=true
stdout_logfile=/home/username/logs/queue-worker.log
environment=APP_ENV="production",QUEUE_CONNECTION="redis"

Remove any duplicate cron entries that call queue:work:

crontab -e   # comment out lines like * * * * * php /path/artisan queue:work --quiet

3. Optimize Redis

# /etc/redis/redis.conf
maxmemory 256mb
maxmemory-policy allkeys-lru
timeout 0
tcp-backlog 511

Restart Redis:

systemctl restart redis

4. Refresh Composer Autoload

cd /home/username/laravel
composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache
php artisan view:cache

5. Restart All Services

supervisorctl reread
supervisorctl update
supervisorctl restart laravel-queue:*
systemctl restart php8.2-fpm
systemctl restart nginx   # or apache2 if you use Apache
SUCCESS: Your queue workers should now show “RUNNING” in supervisorctl status and the cron log stops spitting “PHP‑FPM SIGSEGV”.

VPS or Shared Hosting Optimization Tips

  • Allocate at least 2 vCPU and 4 GB RAM for a busy Laravel + WordPress combo.
  • Enable opcache.enable=1 and set opcache.memory_consumption=256 in php.ini.
  • Use Cloudflare page rules to cache static assets and reduce queue load.
  • On shared cPanel, place the Laravel project outside public_html and point a sub‑domain to public via Apache Alias or Nginx root.

Real World Production Example

Acme Media ran a Laravel‑based email campaign system behind a WordPress blog on a 2 vCPU VPS. After the fix:

MetricBeforeAfter
Queue Lag (seconds)120 s3 s
CPU Utilization92 %38 %
Page Load (WordPress)4.8 s1.6 s

Before vs After Results

# Before (cron spam)
[Thu Aug 10 00:01:00 2024] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted...
# After (clean supervisor)
[Thu Aug 10 00:01:00 2024] INFO: Worker started successfully – PID 3421

Security Considerations

  • Run Supervisor and PHP‑FPM under the same unprivileged user as your cPanel account.
  • Set open_basedir restrictions in php.ini to limit file system exposure.
  • Keep Redis bound to 127.0.0.1 and enable requirepass in redis.conf.
  • Use ufw to allow only HTTP/HTTPS and SSH.

Bonus Performance Tips

TIP: Enable php artisan horizon for a Horizon dashboard that visualizes queue health, latency, and failed jobs in real‑time.
  • Switch to redis queue driver if you’re still on database – it reduces DB lock contention.
  • Set DB_CONNECTION=mysql with mysqli.reconnect=1 and innodb_flush_log_at_trx_commit=2 for lower latency.
  • Leverage HTTP/2 on Nginx with ssl_protocols TLSv1.2 TLSv1.3 to speed up WordPress asset delivery.

FAQ Section

Q: My queue still won’t start after editing Supervisor?

A: Check the Supervisor log at /var/log/supervisor/laravel-queue.log. Common errors are missing .env variables or permission denied on storage/logs.

Q: Can I use this fix on shared hosting without root?

Yes, but you’ll need to use cPanel’s “Cron Jobs” to run a single php artisan horizon process and rely on the hosting provider’s built‑in PHP‑FPM pool. Make sure proc_open is enabled.

Q: Should I switch to Docker?

Docker isolates PHP‑FPM, Nginx, and Redis, eliminating many VPS‑wide conflicts. However, on a low‑budget cPanel VPS the added layer may increase memory usage.

Final Thoughts

Queue workers crashing on a cPanel VPS is rarely a “Laravel bug”. It’s an infrastructure mismatch that can be solved with a few precise configuration tweaks. By aligning PHP‑FPM pool limits, cleaning up Supervisor, and tightening Redis, you unlock the true speed of Laravel‑powered APIs while keeping your WordPress front‑end buttery smooth.

Stay disciplined: version‑control your supervisord.d files, monitor php-fpm metrics, and schedule a weekly composer dump‑autoload. The result? Faster APIs, happier users, and a stack that scales without endless support tickets.

Monetize Your Optimized Stack

If you’re looking for a cheap, secure VPS that ships with built‑in Laravel support, try Hostinger’s cloud VPS. They offer 2 vCPU, 4 GB RAM, and a one‑click Laravel installer—perfect for developers who want performance without the headache.

No comments:

Post a Comment