Apache can serve a PHP front controller through PHP-FPM while protecting internal source files.
What It Does and When to Use It
Check syntax and required modules before reloading Apache. 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. Restrict direct access to private directories and distinguish rewrite rules from PHP execution.
Example 1: Basic Operation
Check syntax and required modules before reloading Apache.
apachectl configtest
apachectl -M | grep -E 'proxy_fcgi|rewrite'
Example 2: Behavior and Validation
Route permitted PHP files to the correct FPM socket; terminate TLS at an appropriate trusted layer.
<VirtualHost *:80>
ServerName app.example.test
DocumentRoot /srv/app/public
<Directory /srv/app/public>
Require all granted
AllowOverride None
FallbackResource /index.php
</Directory>
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php8.4-fpm.sock|fcgi://localhost/"
</FilesMatch>
</VirtualHost>
Practical Example: Application Use
Validate and reload only after syntax check; the health response must reflect the application.
apachectl configtest && sudo systemctl reload apache2
curl -I http://localhost/health
Important Behavior and Edge Cases
The second example highlights: Route permitted PHP files to the correct FPM socket; terminate TLS at an appropriate trusted layer. The practical example adds: Validate and reload only after syntax check; the health response must reflect the application.
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 | Restrict direct access to private directories and distinguish rewrite rules from PHP execution. |
Key Takeaways
- Apache can serve a PHP front controller through PHP-FPM while protecting internal source files.
- Validate and reload only after syntax check; the health response must reflect the application.
- Check the effective configuration in the SAPI serving requests before changing production.