• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here: Home » Install, Configure Brotli On Apache, WordPress, W3TC

By Abhishek Ghosh June 12, 2017 9:19 am Updated on June 12, 2017

Install, Configure Brotli On Apache, WordPress, W3TC

Advertisement

Previously we talked about Brotli compression in context of Nginx web server. Here is an all in one guide to install, configure Brotli on Apache, WordPress, W3TC running on Ubuntu 16.04 on dedicated server, cloud server instance. In order to follow this guide, you need SSH access and HTTPS/SSL/TLS to be active on your server/website. You can perform the steps on production server with running website with minimal downtime for restarting Apache an optional reboot.
Install, Configure Brotli On Apache, WordPress, W3TC

 

Install, Configure Brotli On Apache On Ubuntu 16.04

 

We need to install the module, setup, configure on Apache. For testing this guide we used latest Ubuntu 16.04 and Apache with all updates up to Jun 12, 2017. We install Apache from our mentioned ondrej’s repo in old guides and configure SSL in this method we described.

SSH to your server. First update, upgrade and install Brotli library :

Advertisement

---

Vim
1
2
3
apt update
apt upgrade
apt-get install brotli

Then install the dependencies needed to build :

Vim
1
sudo apt-get install autoconf automake pkg-config libgtk-3-dev libtool apache2-dev

We will build Apache Brotli Module from this repo :

Vim
1
https://github.com/kjdev/apache-mod-brotli

Change directory to anywhere on your server other than any public directory, /opt, /root all are suitable locations. Do these steps :

Vim
1
2
3
git clone --depth=1 --recursive https://github.com/kjdev/apache-mod-brotli.git
cd apache-mod-brotli
ls

You’ll see these files :

Vim
1
2
autogen.sh  configure.ac  Makefile.am   README.md
brotli      LICENSE       mod_brotli.c  tests

Now run these commands one by one, they’ll take some time :

Vim
1
2
./autogen.sh
./configure

At the end, you’ll receive this kind of message :

Vim
1
make[1]: Leaving directory '/../apache-mod-brotli'

Now run ls :

Vim
1
ls

You’ll see lot of new files :

Vim
1
2
3
4
5
6
7
8
aclocal.m4      config.h.in    libtool      mod_brotli.c
ar-lib          config.log     LICENSE      mod_brotli.la
autogen.sh      config.status  ltmain.sh    mod_brotli_la-mod_brotli.lo
autom4te.cache  config.sub     m4           mod_brotli_la-mod_brotli.o
brotli          configure      Makefile     README.md
compile         configure.ac   Makefile.am  stamp-h1
config.guess    depcomp        Makefile.in  tests
config.h        install-sh     missing

After the step of make, we run install command. Here we will run this command :

Vim
1
install -D .libs/mod_brotli.so /usr/lib/apache2/modules/mod_brotli.so -m 644

Now, change directory to Apache’s module’s directory :

Vim
1
cd /etc/apache2/mods-available

Make sure that you are in the above directory. Create the load file :

Vim
1
echo "LoadModule brotli_module /usr/lib/apache2/modules/mod_brotli.so" > brotli.load

Next we need to create brotli.conf file with the following content, it is a generalised configuration, you can tweak later :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<IfModule brotli_module>
  # Compression
  ## BrotliCompressionLevel: 0-11 (default: 11)
  BrotliCompressionLevel 10
  ## BrotliWindowSize: 10-24 (default: 22)
  BrotliWindowSize 22
 
  # Logging
  # Filter note
  BrotliFilterNote Input  brotli_in
  BrotliFilterNote Output brotli_out
  BrotliFilterNote Ratio  brotli_ratio
 
  #LogFormat '"%r" %{brotli_out}n/%{brotli_in}n (%{brotli_ratio}n)' brotli
  #CustomLog ${APACHE_LOG_DIR}/brotli_access.log brotli
 
  # Output filter
  AddOutputFilterByType BROTLI text/html text/plain text/css text/xml
  AddOutputFilterByType BROTLI text/css
  AddOutputFilterByType BROTLI application/x-javascript application/javascript
  AddOutputFilterByType BROTLI application/rss+xml
  AddOutputFilterByType BROTLI application/xml
  AddOutputFilterByType BROTLI application/json
 
  # Global output filer if necessary.
  # SetOutputFilter BROTLI
  # SetEnvIfNoCase Request_URI \.txt$ no-br
 
</IfModule>

of course later you can add more types :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
AddOutputFilterByType BROTLI application/javascript
AddOutputFilterByType BROTLI application/rss+xml
AddOutputFilterByType BROTLI application/vnd.ms-fontobject
AddOutputFilterByType BROTLI application/x-font
AddOutputFilterByType BROTLI application/x-font-opentype
AddOutputFilterByType BROTLI application/x-font-otf
AddOutputFilterByType BROTLI application/x-font-truetype
AddOutputFilterByType BROTLI application/x-font-ttf
AddOutputFilterByType BROTLI application/x-javascript
AddOutputFilterByType BROTLI application/xhtml+xml
AddOutputFilterByType BROTLI application/xml
AddOutputFilterByType BROTLI font/opentype
AddOutputFilterByType BROTLI font/otf
AddOutputFilterByType BROTLI font/ttf
AddOutputFilterByType BROTLI image/svg+xml
AddOutputFilterByType BROTLI image/x-icon
AddOutputFilterByType BROTLI text/css
AddOutputFilterByType BROTLI text/html
AddOutputFilterByType BROTLI text/javascript
AddOutputFilterByType BROTLI text/plain
AddOutputFilterByType BROTLI text/xml

Enable the module :

Vim
1
a2enmod brotli

Restart Apache :

Vim
1
systemctl restart apache2

Now, if you go to test on some online tools like :

Vim
1
https://tools.keycdn.com/brotli-test

You’ll see that your site supports brotli.

 

Alternative Ready To Use Solution

 

This is not exactly recommended way by quick. If you followed the above procedure, then the end, you got three files. Those three files you can download by clicking the below link :

https://thecustomizewindows.com/Downloads/brotli.tar.gz

If you wget from our site, uncompress it :

Vim
1
2
3
4
wget https://thecustomizewindows.com/Downloads/brotli.tar.gz
tar -xzvf brotli.tar.gz
cd /var/www/html/Downloads/brotli
ls

There will be three files – mod_brotli.so, brotli.conf, brotli.load. You’ll place them in :

Vim
1
2
3
/usr/lib/apache2/modules/mod_brotli.so
/etc/apache2/mods-available/brotli.conf
/etc/apache2/mods-available/brotli.load

Enable the module :

Vim
1
a2enmod brotli

Restart Apache :

Vim
1
systemctl restart apache2

Thats it. Here is official documentation from Apache :

Vim
1
https://httpd.apache.org/docs/trunk/mod/mod_brotli.html

 

Configure Brotli On Apache For WordPress, W3TC

 

Now change directory to where your WordPress is installed, like /var/www/html :

Vim
1
cd /var/www/html

Open .htaccess

Vim
1
nano .htaccess

and add this on the top of everything :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
### stanza for brotli starts ###
<IfModule mod_headers.c>
  # Serve brotli compressed CSS files if they exist and the client accepts brotli.
  RewriteCond %{HTTP:Accept-encoding} br
  RewriteCond %{REQUEST_FILENAME}\.br -s
  RewriteRule ^(.*)\.css $1\.css\.br [QSA]
 
  # Serve gzip compressed CSS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.css $1\.css\.gz [QSA]
 
  # Serve brotli compressed JS files if they exist and the client accepts brotli.
  RewriteCond %{HTTP:Accept-encoding} br
  RewriteCond %{REQUEST_FILENAME}\.br -s
  RewriteRule ^(.*)\.js $1\.js\.br [QSA]
 
  # Serve gzip compressed JS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
 
  # Serve correct content types, and prevent mod_deflate double gzip.
  RewriteRule \.css\.gz$ - [T=text/css,E=no-gzip:1]
  RewriteRule \.js\.gz$ - [T=text/javascript,E=no-gzip:1]
  RewriteRule \.css\.br$ - [T=text/css,E=no-gzip:1]
  RewriteRule \.js\.br$ - [T=text/javascript,E=no-gzip:1]
 
  <FilesMatch "(\.js\.gz|\.css\.gz)$">
    # Serve correct encoding type.
    Header set Content-Encoding gzip
    # Force proxies to cache gzipped & non-gzipped css/js files separately.
    Header append Vary Accept-Encoding
  </FilesMatch>
  <FilesMatch "(\.js\.br|\.css\.br)$">
    # Serve correct encoding type.
    Header set Content-Encoding br
    # Force proxies to cache gzipped & non-gzipped css/js files separately.
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>
### stanza for brotli ends ###

It is better to reboot :

Vim
1
reboot

And clear all W3TC cache. We selected CSS, Js. You should know which other files Brotli supports. The above is dynamic compression which occurs on-the-fly when the visitor opens a page. There is static compression, in which the assets are compressed on the disk before the user request. The above module does not provide the static compression function. Basically it is the static compression which is better. If your file was styles.css, it needs to be manually made to styles.css.br. These Google’s stuffs are not so good like old good things. You need to create a script or run command compress the most commonly requested files to brotli. There is a PHP extension available for Brotli :

Vim
1
https://github.com/kjdev/php-ext-brotli

But yet, I never saw WordPress Brotli Plugin which will automate compression and flush from WordPress interface. I will suggest to manually compress only the CSS and Js served from your server (not CDN) to convert to brotli. From tests like webpagetest.org, you can see which CSS, Js files from your server (not CDN) are commonly served. If a CSS has location :

Vim
1
https://github.com/wp-content/themes/some.css

On server, go to the location wp-content/themes/some.css and convert it to brotli. Never forget to delete on some change and again recreate. In this way, you are serving some static and some dynamic brotli compressed files. Brotli sources provide C, Java, and Python bindings. You can either use these bindings or just fork/exec the bro tool to directly compress files, they have Python tool but Google’s Python is odd :

Vim
1
https://github.com/google/brotli/tree/master/python

How to easily of it and flush, that I will tell you in future guide. You can read Dropbox’s useful article which is far superior than that of Google’s docs:

Vim
1
https://blogs.dropbox.com/tech/2017/04/deploying-brotli-for-static-content/

Tagged With apache install mod_brotli ubuntu 14 04 , brotli apache WordPress , change wordpress to brotli

This Article Has Been Shared 134 Times!

Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Install, Configure Brotli On Apache, WordPress, W3TC

  • Scalable MySQL Database for WordPress with Rackspace Cloud

    Scalable MySQL Database for WordPress is very easy to create as Rackspace allows Cloud Database,so does Amazon. Here is a guide for high performance WordPress.

  • Installing WordPress via PHP Script : Cloud Sites and Other WebHosts

    Installing WordPress via PHP Script is a very way to install WordPress on your Server via FTP without Shell Access. The script automatically download and unzip.

  • Installing WordPress on Free OpenShift PaaS

    Installing WordPress on Free OpenShift PaaS can be a free way for installing self hosted WordPress. This is a long, detailed video to startup using WordPress.

  • Adding Schema.org Structured Data in Genesis Theme

    Adding Schema.org Structured Data in Genesis Theme without using any plugin is quite easy as Genesis has great documentation and has excellent existing markups.

  • mod_pagespeed and Google PageSpeed Service

    mod_pagespeed and Google PageSpeed Service has been evaluated and from our tests some parts of mod_pagespeed is good but Google PageSpeed Service lags far away.

Additionally, performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • How to Do Electrical Layout Plan for Adding Smart Switches January 26, 2023
  • What is a Data Mesh? January 25, 2023
  • What is Vehicular Ad-Hoc Network? January 24, 2023
  • Difference Between Panel Light, COB Light, Track Light January 21, 2023
  • What is COB LED? How LED Chip On Board Works January 20, 2023

About This Article

Cite this article as: Abhishek Ghosh, "Install, Configure Brotli On Apache, WordPress, W3TC," in The Customize Windows, June 12, 2017, January 27, 2023, https://thecustomizewindows.com/2017/06/install-configure-brotli-on-apache-wordpress-w3tc/.

Source:The Customize Windows, JiMA.in

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
Do not sell my personal information.
Cookie SettingsAccept
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytics
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.
Others
Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.
SAVE & ACCEPT