Install php-ext-brotli on CWP PHP Switcher, CGI Selector and PHP-FPM selector
In this tutorial we’re going to install php-brotli on cwp server with switcher, CGI selector and php-fpm selector. This PHP extension allows Brotli compression which are used to compress files as well as serving cached resources by various applications/plugins.
Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression.
Without wasting time lets get started :
Install Google brotli :
yum install pcre-devel cmake git -y cd /usr/local/src git clone https://github.com/google/brotli.git cd brotli ./configure-cmake make && make install
In CWP there are three php modules i.e switcher (free for all), cgi selector (pro needed) and php-fpm selector (pro needed) ensure you’ve pro licensee in order to use cgi and fpm selector.
Brotli PHP Switcher installation :
cd /usr/local/src rm -rf php-ext-brotli git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git cd php-ext-brotli phpize ./configure make && make install
then add php extension ini file, run below command one by one:
touch /usr/local/php/php.d/brotli.ini grep "brotli.so" /usr/local/php/php.d/brotli.ini || echo "extension=brotli.so" >> /usr/local/php/php.d/brotli.ini
Brotli PHP Selector (CGI) installation :
cd /usr/local/src rm -rf php-ext-brotli git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git cd php-ext-brotli /opt/alt/php74/usr/bin/phpize ./configure --with-php-config=/opt/alt/php74/usr/bin/php-config make && make install
then add php extension ini file, run below command one by one:
touch /opt/alt/php74/usr/php/php.d/brotli.ini grep "brotli.so" /opt/alt/php74/usr/php/php.d/brotli.ini || echo "extension=brotli.so" >> /opt/alt/php74/usr/php/php.d/brotli.ini
Here you need to change highlighted in red for other php cgi selector version i.e.
replace php74 with php73 for php 7.3.x installation
replace php74 with php72 for php 7.2.x installation
replace php74 with php71 for php 7.1.x installation
replace php74 with php70 for php 7.0.x installation
replace php74 with php56 for php 5.6.x installation
Brotli PHP-FPM Selector installation :
cd /usr/local/src rm -rf php-ext-brotli git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git cd php-ext-brotli /opt/alt/php-fpm74/usr/bin/phpize ./configure --with-php-config=/opt/alt/php-fpm74/usr/bin/php-config make && make install
then add php extension ini file, run below command one by one:
touch /opt/alt/php-fpm74/usr/php/php.d/brotli.ini grep "brotli.so" /opt/alt/php-fpm74/usr/php/php.d/brotli.ini || echo "extension=brotli.so" >> /opt/alt/php-fpm74/usr/php/php.d/brotli.ini
Here you need to change highlighted in red for other php-fpm selector version i.e.
replace php-fpm74 with php-fpm73 for php 7.3.x installation
replace php-fpm74 with php-fpm72 for php 7.2.x installation
replace php-fpm74 with php-fpm71 for php 7.1.x installation
replace php-fpm74 with php-fpm70 for php 7.0.x installation
replace php-fpm74 with php-fpm56 for php 5.6.x installation
after that restart/reload php-fpm service from cwp php-fpm module.
Hi,
I brotli worked fine for me on CWP7 for a long time but after updating to nginx 1.20.2 it is no longer working and is complaining about the load_modules lines in the nginx.conf because of some verions he expected.
i tried your steps to re install it for php-fpm but it doesn’t worked.
I also recorgnized in your tutorial the file is called brotli.so, the ones i always used was called:
#load_module “modules/ngx_http_brotli_filter_module.so”;
#load_module “modules/ngx_http_brotli_static_module.so”;
i uncommented all brotli related stuff in the config file as it is no longer working.
Any ideas how to fix it?
The only thing i changed was the nginx update
thanks
Hi. What if I get permission denied when executing a command?
# /opt/alt/php-fpm71/usr/bin/phpize
bash: /opt/alt/php-fpm71/usr/bin/phpize: Permission denied
===
# cd /opt/alt/php-fpm71/usr/bin/
# ls
pear peardev pecl phar phar.phar php php-cgi php-config phpdbg phpize
#
are you using `root` user or something else ?
Hello, I have CWP PRO and I have done everything that it indicates, however it continues to indicate that brotli is not active
then you missed something . provide more info
I am no expert whatsoever, but I think you have an error on this command (why “grep imagick.so?)
touch /usr/local/php/php.d/brotli.ini
grep “imagick.so” /usr/local/php/php.d/brotli.ini || echo “extension=brotli.so” >> /usr/local/php/php.d/brotli.ini
thanks it is now corrected.