Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got the mod_deflate up and running. I can throw in a something.txt file in my apache server and use curl to check it out.

curl --compressed -I /somefile.txt gives me back the following which is good and compressed:

Vary: Accept-Encoding
Content-Encoding: gzip

But if i use /some.php i get back:

Accept-Ranges: bytes
X-Powered-By: PHP/5.4.4-14+deb7u5

But no Content-Encoding: gzip, the .htaccess i used with multiple options:

SetOutPutFilter DEFLATE

Or

AddOutputFilterByType DEFLATE application/json

I also checked if the zlib compression was turned off in the php.ini and also tried to set the output buffer to off. But no matter what i try i never get the php output to be compresse by apache. The overhead from apache to zip it is less than when i use php zlib.

I see enough posts like Apache output compression working for CSS/JS but not PHP but that enables compression from php. I want apache to handle it.

I must be missing something silly here.

UPDATE: I resolved all issues, also because of the answers given. In the end it still didn't work 100%. This was due to the wrong package installed. apache2filter was used which send me on the wrong path.

share|improve this question
    
php is application/x-httpd-php not application/json –  yoonix Nov 15 '13 at 3:11
    
in the php i actually set the header to application/json and verified it was coming in as such. I persume that it listens to the header i set. –  Erik-Jan Riemers Nov 15 '13 at 8:34
    
check for php extension in your configuration, do you have something like AddOutputFilter (.... things ...) php? –  regilero Nov 15 '13 at 12:53

3 Answers 3

up vote 2 down vote accepted

AddOutputFilterByType is a deprecated way of adding things on the output filter chain (ref here ).:

One further directive AddOutputFilterByType is still supported, but may be problematic and is now deprecated. Use dynamic configuration instead.

And you may have some problems because PHP is associated with one filter chain which does not contain the DEFLATE filter.

You could try to use the new syntax of mod_filter with FilterChain as shown in this question (in the question, not in the answers).

share|improve this answer
    
I added this in the .htaccess file and now i got the "Content-Encoding: gzip" back. Thanks! A hard find since the whole internet is filled with outputfiltertypes and such. –  Erik-Jan Riemers Nov 15 '13 at 14:53
    
Not related to the original question, but using a load test tool like "siege" or "ab" from apache doesn't get the compressed file even though it support gzip now. –  Erik-Jan Riemers Nov 15 '13 at 15:08
    
@Erik-JanRiemers: do not forget to upvato the Op question on Stack Overflow then. –  regilero Nov 15 '13 at 16:34

I had this problem and ended up discovering that setting the mod_deflate options in .htaccess vs. httpd.conf led to different results. The httpd.conf settings worked for PHP when run in fastcgi or as a DSO. In the .htaccess file, PHP running as fastcgi couldn't grok the deflate directives.

So try to write the rules in your httpd.conf instead of .htaccess and see if that solves your problem (don't forget to restart your Apache after making the changes).

share|improve this answer
    
I tried both the .htaccess and the /etc/apache2/mods-enabled/deflate.conf but no luck. I did restart in between. I might want to give that fastcgi a try. Almost certain its a php <-> apache issue since apache gzip's all other files just fine. –  Erik-Jan Riemers Nov 15 '13 at 7:40
    
With the deflate.conf were you able to test showing compression working for other non-PHP files? If not, did you have an include statement in your httpd.conf? ie. Include /etc/apache2/mods-enabled/deflate.conf Just wanting to rule out those possibilities. Otherwise, I wonder if you could test with using mod_php vs. fast-cgi to see if you get any different results. –  VogonPoetLaureate Nov 15 '13 at 11:51
    
As shown in my OP i did test with curl to show that other files are indeed compressed. I need to check out the other php options and see what they do too. –  Erik-Jan Riemers Nov 15 '13 at 14:45

Try this and see if it works for you:

AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
share|improve this answer
    
I added these lines to the .htaccess and deflate.conf as a test but didn't help. Output still does not say it has gzip. –  Erik-Jan Riemers Nov 15 '13 at 7:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.