Debugging “Error parsing script headers” and Segfaults in Apache + PHP-FPM with mod_deflate Configuration


6 views

After setting up PHP-FPM with Apache 2.4 using proxy_fcgi, I encountered intermittent blank pages (WSOD - White Screen of Death) occurring approximately every 4-6 requests. The issue primarily affected my main domain (http://danielhe.com/) while subdomain vhosts remained unaffected.

The Apache error logs revealed two distinct but related issues:

[client x.x.x.x] AH01070: Error parsing script headers
...
AH00052: child pid 9740 exit signal Segmentation fault (11)

The "Error parsing script headers" could be consistently reproduced by:

  • Refreshing the page multiple times
  • The segmentation faults appeared randomly after several occurrences of the header parsing errors

After extensive testing, I discovered that mod_deflate was causing conflicts in the header processing chain. The following configuration from Apache's documentation resolved both the segmentation faults and the WSOD issues:

SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpeg|jpg|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

For PHP-FPM with proxy_fcgi, ensure these settings in your Apache configuration:

<FilesMatch "\.php$">
    SetHandler "proxy:fcgi://127.0.0.1:9000"
    # Timeout settings
    ProxyTimeout 300
</FilesMatch>

# Disable output compression for specific PHP scripts
<Location "/special-handler.php">
    SetEnv no-gzip 1
</Location>
  1. Verify PHP-FPM configuration: Check pm.max_children settings match your server capacity
  2. Enable core dumps: Configure your system to capture Apache core dumps for segmentation faults
  3. Test with mod_deflate disabled: Temporarily disable compression to verify it's the root cause

If the issue persists, consider these alternatives:

# Option 1: Disable mod_deflate for PHP files
<FilesMatch "\.(php|phar)$">
    SetEnv no-gzip 1
</FilesMatch>

# Option 2: Use alternative compression module
LoadModule brotli_module modules/mod_brotli.so

After setting up PHP-FPM with Apache 2.4 using proxy_fcgi, everything seemed to work fine - until every 4-6 requests returned blank pages. The issue appeared on my primary domain (http://danielhe.com/) while subdomain vhosts remained unaffected.

Apache's error log showed two critical patterns:

[client x.x.x.x] AH01070: Error parsing script headers
[core:notice] AH00052: child pid 9740 exit signal Segmentation fault (11)

The "Error parsing script headers" could be consistently reproduced by refreshing the page multiple times. The segmentation faults appeared more randomly, typically following several occurrences of the header parsing errors.

Three key observations emerged:

1. The issue was specific to the main vhost configuration
2. PHP-FPM pool processes weren't crashing
3. Memory limits appeared adequate

After extensive testing, the root cause pointed to mod_deflate compression issues. The solution came from Apache's documentation with these specific configurations:

SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpeg|jpg|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

For complete stability, consider these additional PHP-FPM settings:

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

To verify the fix:

ab -n 1000 -c 10 http://yoursite.com/test.php
tail -f /var/log/apache2/error.log

Monitor for both header parsing errors and segmentation faults. The test should complete without either error occurring.

Ensure these elements are properly configured:

☑ Proper MPM module (prefork or worker)
☑ Correct ProxyPassMatch configuration
☑ Appropriate PHP-FPM pool settings
☑ mod_deflate configured as shown above
☑ Sufficient memory allocation