Enable brotli on linux web app (Apache2 mod_brotli)

moo2u2 41 Reputation points
2021-03-06T01:15:18.773+00:00

I'm running a PHP website on a linux web app.
/usr/sbin/apache2 -v output says I'm running Apache 2.4.38
apache2ctl -M lists brotli_module as present, and ls /etc/apache2/mods-enabled/ contains brotli, so it appears to be enabled.
However phpinfo curl section lists Brotli = No, and brotli tester sites list it as not enabled.

Is there an extra step to enable brotli for my pages / JS / CSS? Please tell me I'm just missing something obvious here :)

Thanks!

Update:

I have tried running

a2enmod brotli
service apache2 restart

and adding the following to my .htaccess file

AddOutputFilterByType BROTLI_COMPRESS text/css text/csv text/html text/plain text/richtext text/sgml text/tab-separated-values application/javascript application/x-javascript httpd/unix-directory

but now I'm getting a 500 response and the following in my logs:

Unknown filter provider BROTLI_COMPRESS

(I've tried the same with just BROTLI with the same error)

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,789 questions
{count} votes

Accepted answer
  1. SnehaAgrawal-MSFT 18,191 Reputation points
    2021-03-12T05:12:59.283+00:00

    Thanks for reply! The modsecurity package is an example. You can do the same for steps for brotli, you need to create a custom startup.sh file and add the steps for brotli install in that script. You can then update the startup command in portal to point to startup.sh

    You may follow the steps here: How To Enable Brotli Compression In Apache 2.4 (bash-prompt.net)

    Check the sample startup script to enable brotli apache module

    After following the test instructions from the first link the line content-encoding: br from the output indicates that the server supports serving pages with brotli.

    Hope this helps.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. SnehaAgrawal-MSFT 18,191 Reputation points
    2021-03-09T16:32:44.687+00:00

    Thanks for reply! You may try this, As process should be similar to installing any other apache module in php app running with blessed image.

    Here is an example for adding/removing headers using a custom startup script:

    !/bin/bash

    a2enmod headers
    echo "Header set MyHeader \"%D %t"\" >> /etc/apache2/apache2.conf
    echo "Header always unset \"X-Powered-By\"" >> /etc/apache2/apache2.conf
    echo "Header unset \"X-Powered-By\"" >> /etc/apache2/apache2.conf

    apt-get update
    apt-get install libapache2-modsecurity -y
    sed -i '/^</IfModule>/i SecRuleEngine On' /etc/apache2/mods-enabled/security2.conf
    sed -i '/^</IfModule>/i SecStatusEngine On' /etc/apache2/mods-enabled/security2.conf
    sed -i '/^</IfModule>/i ServerTokens Full' /etc/apache2/mods-enabled/security2.conf
    sed -i '/^</IfModule>/i SecServerSignature " "' /etc/apache2/mods-enabled/security2.conf

    /usr/sbin/apache2ctl -D FOREGROUND

    Hope this helps. Let us know.

    1 person found this answer helpful.