A basic Apache/FPM setup needs a document root pointing at public and an index PHP handler.
What It Does and When to Use It
Route PHP through a correctly configured web-server-to-FPM boundary. The web server handles HTTP, the PHP worker executes scripts, and CLI has separate configuration and lifecycle.
Requirements, Inputs and Expected Behavior
Confirm the runtime, extension, environment variables, and permissions before running the examples in production. Confirm the CLI binary and web SAPI load the correct extensions and INI files.
Example 1: Basic Operation
Route PHP through a correctly configured web-server-to-FPM boundary.
<Directory /srv/demo/public>
Require all granted
DirectoryIndex index.php
</Directory>
Example 2: Behavior and Validation
Verify web execution and distinguish PHP-FPM from PHP CLI.
<?php
header('Content-Type: text/plain; charset=utf-8');
echo 'Running PHP ',PHP_VERSION,' via ',PHP_SAPI;
Practical Example: Application Use
Inspect the HTTP response and the worker service before investigating application code.
curl -sSI http://localhost/
php --ini
sudo systemctl status php8.4-fpm --no-pager
Important Behavior and Edge Cases
The second example highlights: Verify web execution and distinguish PHP-FPM from PHP CLI. The practical example adds: Inspect the HTTP response and the worker service before investigating application code.
Comparison with Related Approaches
| Approach | What changes |
|---|---|
| Web server, worker and PHP CLI | The web server handles HTTP, the PHP worker executes scripts, and CLI has separate configuration and lifecycle. |
| Choosing safely | Check the effective configuration in the SAPI serving requests before changing production. |
Common Beginner Mistakes
| Mistake | Correct approach |
|---|---|
| Checking the PHP CLI INI instead of FPM | Inspect phpinfo or configuration through the protected web SAPI. |
| Exposing worker status publicly | Restrict FPM diagnostics to localhost or a monitored private network. |
| Skipping operational constraints | Confirm the CLI binary and web SAPI load the correct extensions and INI files. |
Key Takeaways
- A basic Apache/FPM setup needs a document root pointing at public and an index PHP handler.
- Inspect the HTTP response and the worker service before investigating application code.
- Check the effective configuration in the SAPI serving requests before changing production.