Here’s the complete blog post including both standard PHP installations and CloudLinux servers with PHP 8.1:
Enable Browscap in PHP 8.1
Browscap (Browser Capability) is a feature in PHP that helps in detecting browser capabilities. Whether you are using a standard PHP installation or running CloudLinux, this guide will walk you through enabling browscap for PHP 8.1.
For Standard PHP Installations
Step 1: SSH into Your Server
- Open your terminal.
- SSH into your server:
ssh root@your-server-ip
Replace your-server-ip with your server’s IP address.
Step 2: Navigate to the PHP 8.1 Configuration Directory
- Change to the PHP 8.1 configuration directory:
cd /opt/cpanel/ea-php81/root/etc/php.d
Step 3: Download the Browscap File
- Download the latest
browscap.inifile:
wget https://browscap.org/stream?q=PHP_BrowsCapINI
- Rename the downloaded file:
mv stream\?q\=PHP_BrowsCapINI php_browscap.ini
Step 4: Edit the php.ini File
- Open the
php.inifile:
vim /opt/cpanel/ea-php81/root/etc/php.ini
- Add or modify the
[browscap]section:
[browscap]
browscap = /opt/cpanel/ea-php81/root/etc/php_browscap.ini
- Save and close the file.
Step 5: Restart Apache
- Restart Apache:
service httpd restart
(Use apache2 if applicable.)
Step 6: Verify the Configuration
- Create a PHP file (e.g.,
info.php) with:
<?php
$browser = get_browser();
print_r($browser);
phpinfo();
?>
- Access this file through your web browser and check for the
browscapdirective.
For CloudLinux Servers
Step 1: Download the Browscap Configuration File
- Download the
browscap.inifile:
wget https://browscap.org/stream?q=PHP_BrowsCapINI
- Move the file to the directory for PHP 8.1:
mv stream\?q\=PHP_BrowsCapINI /opt/alt/php81/etc/php.d.all/browscap.ini
Step 2: Edit the php.ini File
- Open the PHP 8.1
php.inifile:
vim /opt/alt/php81/etc/php.ini
- Locate or add the
[browscap]section:
[browscap]
browscap = /opt/alt/php81/etc/php.d.all/browscap.ini
- Save and close the file.
Note: Repeat these steps for each PHP version if browscap needs to be enabled globally.
Step 3: Rebuild CageFS Parameters
- Rebuild the PHP configuration within CageFS:
cagefsctl --rebuild-alt-php-ini
cagefsctl --force-update
Step 4: Test the Configuration
- Create a PHP file (e.g.,
test_browscap.php) with:
<?php
$browser = get_browser(null, true);
print_r($browser);
phpinfo();
?>
- Access this file through your web server to check if
browscapis functioning correctly.
Conclusion
Test the PHP Code given earlier, it should give you the output like this:
stdClass Object ( [browser_name_regex] => ~^mozilla/5\.0 \(.*linux.*\) applewebkit.* \(.*khtml.*like.*gecko.*\) chrome/128\.0.*safari/.*$~ [browser_name_pattern] => Mozilla/5.0 (*Linux*) applewebkit* (*khtml*like*gecko*) Chrome/128.0*Safari/* [parent] => Chrome 128.0 [platform] => Linux [comment] => Chrome 128.0 [browser] => Chrome [browser_maker] => Google Inc [version] => 128.0 [majorver] => 128 [device_type] => Desktop [device_pointing_method] => mouse [minorver] => 0 [ismobiledevice] => [istablet] => [crawler] => )
Enabling browscap for PHP 8.1 allows for accurate browser detection and improved user experience. Whether you are working with a standard PHP installation or a CloudLinux server, these steps will help you configure browscap effectively. Keep your browscap.ini file updated to ensure accurate browser capability data.
Feel free to adjust these instructions based on your specific server setup and PHP versions.
This comprehensive guide covers enabling browscap in both standard and CloudLinux environments, ensuring you can effectively manage browser capability detection.

