Fix PHP-FPM Not Working in Nginx (Complete Troubleshooting Guide 2026)

If your website is showing errors like:

  • 502 Bad Gateway
  • 504 Gateway Timeout
  • Blank white page
  • PHP files downloading instead of executing

Then your PHP-FPM is not working correctly with Nginx.

This is a very common issue on VPS and cloud servers.

In this guide, you’ll learn how to fix it step-by-step.


🚨 Common Error Messages

  • connect() to unix:/run/php/php-fpm.sock failed
  • 502 Bad Gateway
  • No input file specified
  • Primary script unknown

🔍 Step 1: Check PHP-FPM Status

Run:

systemctl status php-fpm

Or:

systemctl status php8.2-fpm

If stopped:

systemctl start php-fpm

Enable auto start:

systemctl enable php-fpm

⚙️ Step 2: Verify Socket or Port

Check config:

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

Look for:

listen = /run/php/php8.2-fpm.sock

OR:

listen = 127.0.0.1:9000

🔧 Step 3: Match Nginx Config

Open:

nano /etc/nginx/sites-available/default

Ensure:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}

👉 Socket must match PHP config exactly.


🔥 Step 4: Fix Permissions Issue

chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html

Edit:

nano /etc/php/8.2/fpm/pool.d/www.conf
user = www-data
group = www-data
listen.owner = www-data
listen.group = www-data

Restart:

systemctl restart php8.2-fpm
systemctl restart nginx

🚀 Step 5: Increase PHP-FPM Limits

Edit:

nano /etc/php/8.2/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20

⚡ Step 6: Check Logs

tail -f /var/log/php8.2-fpm.log
tail -f /var/log/nginx/error.log

Look for:

  • Socket errors
  • Permission denied
  • Timeout issues

🛡️ Step 7: Fix 502 Bad Gateway

Most common fix:

systemctl restart php8.2-fpm
systemctl restart nginx

If still issue:

Switch to TCP:

fastcgi_pass 127.0.0.1:9000;

💡 Step 8: Install Missing PHP Extensions

apt install php8.2-mysql php8.2-curl php8.2-xml php8.2-mbstring

Restart:

systemctl restart php8.2-fpm

⚙️ Step 9: Optimize Nginx for PHP

Add:

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;

🚀 Step 10: Use High Performance Hosting

Low-quality VPS often causes PHP-FPM crashes.

👉 Recommended:

The Ultimate Managed Hosting Platform

🔥 Bonus: Debug Script

Create file:

nano /var/www/html/info.php

Add:

<?php phpinfo(); ?>

Visit:

yourdomain.com/info.php

If not working → PHP-FPM issue confirmed.


📊 Advanced Fixes

Enable OPcache

nano /etc/php/8.2/fpm/php.ini
opcache.enable=1
opcache.memory_consumption=128

Tune Kernel Limits

ulimit -n 65535

❓ FAQs

Why PHP-FPM stops working?

  • Memory issues
  • Misconfiguration
  • Permission errors

Socket vs Port — which is better?

Socket is faster.


🏁 Conclusion

PHP-FPM issues can break your entire website.

But once fixed properly:

  • Your site becomes fast
  • Errors disappear
  • Server load reduces

🚀 Pro Tip

Use:

  • Nginx + PHP-FPM
  • Cloudflare
  • Caching

This combo gives maximum performance + minimum issues.


🎯 Final Recommendation

👉 Get optimized server setup:

The Ultimate Managed Hosting Platform

Fix it once, and your server will run smoothly for months without issues.


Similar Posts

Leave a Reply

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