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


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.

  • php is application/x-httpd-php not application/json
    – user143703
    Nov 15, 2013 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. Nov 15, 2013 at 8:34
  • check for php extension in your configuration, do you have something like AddOutputFilter (.... things ...) php?
    – regilero
    Nov 15, 2013 at 12:53

3 Answers 3


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).

  • 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. Nov 15, 2013 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. Nov 15, 2013 at 15:08
  • @Erik-JanRiemers: do not forget to upvato the Op question on Stack Overflow then.
    – regilero
    Nov 15, 2013 at 16:34
  • 1
    "AddOutputFilterByType is a deprecated way" - This would seem to relate to Apache 2.2 only. It appears to have been updated (and un-deprecated) in Apache 2.4 ... "Had severe limitations before being moved to mod_filter in version 2.3.7" - httpd.apache.org/docs/2.4/mod/…
    – MrWhite
    Oct 7, 2020 at 16:08

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).

  • 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. Nov 15, 2013 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. Nov 15, 2013 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. Nov 15, 2013 at 14:45

Try this and see if it works for you:

AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
  • 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. Nov 15, 2013 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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