This guide will walk you through installing the php-ext-brotli extension on a CWP (Control Web Panel) server. The Brotli extension enhances performance by compressing data, which is beneficial for serving cached resources in various applications. Follow the steps below to install php-ext-brotli for PHP Switcher, CGI Selector, and PHP-FPM Selector.
Understanding Brotli Compression
Brotli is a lossless compression algorithm that combines:
- A modern variant of the LZ77 algorithm,
- Huffman coding, and
- Second-order context modeling.
It provides compression rates comparable to the best available methods while maintaining speeds similar to the Deflate algorithm but with denser compression.
Prerequisites
Before starting, ensure the following:
- A CWP Pro license is required to use the CGI and PHP-FPM selectors.
- Root access to the server.
Installation
Step 1: Install Google Brotli
Begin by installing the Brotli library:
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
Step 2: Installing php-ext-brotli
A. PHP Switcher Installation
1. Download and build the extension:
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
2. Add the extension to PHP:
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
B. PHP Selector (CGI) Installation
1. Download and build the extension:
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
2. Add the extension to PHP:
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
3. Adjust for other versions: Replace php74 with the corresponding version:
- php73 for PHP 7.3.x
- php72 for PHP 7.2.x
- php71 for PHP 7.1.x
- php70 for PHP 7.0.x
- php56 for PHP 5.6.x
C. PHP-FPM Selector Installation
1. Download and build the extension:
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
2. Add the extension to PHP:
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
3. Adjust for other versions: Replace php-fpm74 with the corresponding version:
- php-fpm73 for PHP 7.3.x
- php-fpm72 for PHP 7.2.x
- php-fpm71 for PHP 7.1.x
- php-fpm70 for PHP 7.0.x
- php-fpm56 for PHP 5.6.x
Step 3: Restart PHP-FPM
After completing the installation, restart or reload the PHP-FPM service using the CWP PHP-FPM module to apply the changes.
That’s It!
By following these steps, you will have successfully installed the php-ext-brotli extension on your CWP server, enabling efficient Brotli compression for your applications.
You May Also Like
- How to Create and Add Swap Space on Linux (CentOS, Ubuntu, CWP, and VestaCP)
- Engage Your Audience: The Key to Effective Website Sales Content
- Advanced PHP Techniques for Hacking Yoast Metadata in WordPress
- 13 mind hacks you can use to drive website engagement
- Enabling TLS 1.3 in NGINX on CWP/CentOS 7/8/EL7/EL8