Apache won't set headers for PHP script
Asked Answered
B

1

5

This .htaccess file:

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 4 month"
</IfModule>
<IfModule mod_headers.c>
    Header merge X-ModHeaders "Yes, it is installed"
</IfModule>

... works as expected in my development box (Windows box, Apache/2.4.10, PHP running as Apache module), where "works" means that it generates the appropriates headers for all resources (static or dynamic).

However, in my production server (Linux box, Apache/2.2.31, PHP running as FastCGI with mod_fcgid/2.3.9) it only works for static assets, not for PHP scripts.

Am I right suspecting that difference comes from the PHP SAPI? Is there a way to fix it so I don't need to duplicate the code that generates HTTP headers?

Brahmanism answered 21/8, 2015 at 18:47 Comment(8)
PHP can edit headers but that doesn't mean it will by default. You should still get these at any rateFerromagnesian
Think the answer here applies: serverfault.com/questions/383011/… ... didn't dig in too deep but read those bug reports it references.Mccarter
Is your production box on shared hosting? This might prevent you from changing certain apache modules...Gerrit
@Mccarter That's certainly my problem but the only answer so far claims it isn't a bug and links a ticket that talks about something else. Yuk..Thimerosal
@LucLaverdure - Yes, it's shared hosting. What exactly would I be able to change if it was a dedicated server?Thimerosal
You'd be able to change everything on dedicated, what shared hosting do you have? There might be solutions looking for something specific to this hosting providerGerrit
Maybe Header always merge X-ModHeaders "Yes, it is installed"?Assay
@Assay Sorry, I've tried all variations and it doesn't seem to be that. If the module generates any output, it's just wiped out.Thimerosal
R
4

If PHP is running via mod_proxy_fcgi there might be no filesystem directory involved, hence no htaccess lookup can occur.

There is a more recent flavor of php+mod_proxy_fcgi now documented in the manual that uses SetHandler instead of ProxyPass -- that allows things like htaccess to be processed because the core actually looks up the URL in the filesystem as a first step.

Rifkin answered 21/8, 2015 at 22:44 Comment(6)
Server is using "mod_fcgid/2.3.9" and .htaccess is certainly executed since other modules work as expected (e.g. mod_rewrite or the AddHandler directive to select the PHP version) and invalid directives cause a Status 500 response.Thimerosal
BTW, I've updated the question with the actual CGI handler I'm using (it wasn't mod_fastcgi but mod_fcgid, my bad)Thimerosal
For me this was the reason: I switched to the PHP Module on my shared hoster, and then Header set worked.Prompt
I eventually got confirmation from HSP support than their mod_fcgid setup prevented custom headers set in .htaccess from working. (I'm terribly sorry for not reporting back at the time!)Thimerosal
@ÁlvaroGonzález do you have more information on this please? You know what exactly they've fixed? I am having the exact same problem...Pisciform
@AdrianFöder They haven't fixed anything as far as I know. My hosting provider's specific set up does not allow those directives to have effect on the files they process. But since the problem only affects PHP files it's trivial to write a PHP workaround using header().Thimerosal

© 2022 - 2024 — McMap. All rights reserved.