Content · Web Development · PHP

Configuring Apache for PHP Applications

Apache can serve a PHP front controller through PHP-FPM while protecting internal source files.

1 views Published Oct 17, 2026 Updated Oct 17, 2026 Admin

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


ApproachWhat changes
Web server, worker and PHP CLIThe web server handles HTTP, the PHP worker executes scripts, and CLI has separate configuration and lifecycle.
Choosing safelyCheck the effective configuration in the SAPI serving requests before changing production.

Common Beginner Mistakes


MistakeCorrect approach
Checking the PHP CLI INI instead of FPMInspect phpinfo or configuration through the protected web SAPI.
Exposing worker status publiclyRestrict FPM diagnostics to localhost or a monitored private network.
Skipping operational constraintsRestrict 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.
Share this resourceSend this page to someone who may find it useful.