Install Brotli Apache Module and PHP Extension in cPanel EA 4

What is Brotli and Why?

Before we get into details of installing let’s try to understand what exactly is Brotli and how it helps. Brotli is a compression algorithm like gzip but Brotli is one of the best currently available. Brotli is offered by Google officially and is now supported by all modern browsers through various platforms. Brotli can compress HTML, Javascript, CSS better than gzip which help serving web pages faster and achieve possibly the best page load speed.

Prerequisites

  • ROOT user login credentials
  • Access to WHM Panel
  • Access to SSH Terminal

Install Brotli Apache Module

Login to WHM then navigate to Home »Software »EasyApache 4 and click on Customize

easyapache4

then select Apache Modules in the next page and search for mod_brotli

ea4-apache-modules

keep clicking on the Next buttons and finish the installation by clicking Provision in the last step.

Install Brotli PHP Extension

As cPanel doesn’t offer PHP Extension for Brotli through EasyApahe 4 so we will use a custom shell script to install Brotli PHP Extension. Please copy everything below and run at once

for phpver in $(ls -1 /opt/cpanel/ |grep ea-php | sed 's/ea-php//g') ; do
cd ~
git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git
cd ~/php-ext-brotli* || exit
/opt/cpanel/ea-php"$phpver"/root/usr/bin/phpize
./configure --with-php-config=/opt/cpanel/ea-php"$phpver"/root/usr/bin/php-config
make && make install
echo 'extension=brotli.so' > /opt/cpanel/ea-php"$phpver"/root/etc/php.d/brotli.ini
rm -rf ~/php-ext-brotli*
done

this should finish the Brotli PHP Extension installation for you. Please don’t forget to restart Apache (httpd) and PHP-FPM once you finished installation using below commands –

/scripts/restartsrv_httpd; /scripts/restartsrv_apache_php_fpm

Confirm Brotli and Brotli PHP Extension Installation

As we already have installed both Brotli Apache Module and Brotli PHP Extension, let’s verify if they are loaded and ready to use. Please run below command –

httpd -M |grep brotli; php -i |grep “Brotli support”
brotli_module (shared)
Brotli support => enabled

If the output above matches then the installation of Brotli Apache Module and Brotli PHP Extension installation is successful.

Feel free to post comments if you face any issues with this tutorial and I would be happy to help. Also, check out these articles –
How to get Google BBR on CentOS 7
How to get NGINX on cPanel and WHM


3 comments

Leave a Reply to budidayapetani Cancel reply

By Tonmoy Ajize

About Author

Tonmoy Ajize

Hey There! I am Tonmoy Ajize from Dhaka, Bangladesh. I am a Linux System Administrator and Customer Success Specialist.