Apache – Fix Output Compression for PHP

apache-2.2deflategzipPHP

I have this in my .htaccess:

<IfModule mod_deflate.c>
    <FilesMatch "\.(js|css|php)$">
        SetOutputFilter DEFLATE
    </FilesMatch>
</IfModule>

Testing files on my site, it seems that *.js and *.css files are being compressed fine. However, my PHP files are not. These are all direct PHP files, not rewritten in any way or using query parameters – like http://example.com/folder/page.php.

Why would this not be working? I'm on shared hosting so can't change the server myself, but is there something specific I can ask my host to change? (Also, I know about using gzip in PHP, I'd prefer a simpler site-wide solution)

Best Answer

Compression can be enabled php site wide with this entry in "php.ini":

zlib.output_compression = On

or in .htaccess:

php_flag zlib.output_compression on

This site has a good writeup:

[http://www.mybelovedphp.com/2006/11/29/how-to-use-gzip-compression-on-your-php-websites/][1]