Skip to content

How to Configure Apache with PHP-FPM via mod_fcgid or proxy_fcgi

DodaTech Updated 2026-06-24 1 min read

Apache with PHP-FPM via mod_proxy_fcgi provides modern PHP application serving. Unix sockets and proper pool configuration optimize performance. This guide walks through the specific troubleshooting steps to diagnose and resolve PHP-FPM configuration issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

SetHandler fcgid-script (using mod_fcgid)

Wrong: Using outdated mod_fcgid

<FilesMatch \.php$>\n    SetHandler "proxy:fcgi://127.0.0.1:9000"\n</FilesMatch>

Right: Using mod_proxy_fcgi with PHP-FPM

Output

PHP-FPM configured via proxy_fcgi\nHandler: proxy:fcgi://127.0.0.1:9000\nFiles: .php files

Prevention

To avoid future issues, follow these best practices:

  • Use mod_proxy_fcgi instead of mod_fcgid for modern PHP-FPM setups
  • Configure PHP-FPM to listen on a socket or TCP port
  • Set the correct PHP-FPM pool permissions
  • Use ProxyTimeout to avoid gateway timeouts
  • Use to scope the handler to .php files

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with fcgid config

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world APACHE code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

What is the difference between mod_fcgid and mod_proxy_fcgi?|||mod_fcgid manages a pool of CGI processes. mod_proxy_fcgi proxies to an external FastCGI Process manager like PHP-FPM.
Should I use Unix socket or TCP for PHP-FPM? Unix sockets are faster for local setups: SetHandler "proxy:fcgi://unix:/var/run/php/php8.3-fpm.sock".

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro