When configuring PHP on Linux hosting with EasyApache 4, you may need to install PHP extensions across multiple PHP versions. This guide shows how to install extensions using PECL via SSH, either for a single PHP version or for multiple versions simultaneously.
How to do it
-
Step 1: Locate the PECL binary for your PHP version
EasyApache 4 supports multiple PHP versions, and each has its own PECL binary. The path follows this pattern:
/opt/cpanel/ea-php72/root/usr/bin/pecl /opt/cpanel/ea-php73/root/usr/bin/peclReplace the version number (72, 73, etc.) with your target PHP version.
-
Step 2: Install an extension for a single PHP version
Use the
pecl installcommand with the full path to the PECL binary. For example, to install thexmldiffextension for PHP 7.3:/opt/cpanel/ea-php73/root/usr/bin/pecl install xmldiff -
Step 3: Install an extension for multiple PHP versions
To install the same extension across multiple PHP versions (e.g., PHP 7.2 through 8.0), use this loop command:
ls /opt/cpanel/ea-php{72..80}/root/usr/bin/pecl 2>/dev/null | while read phpversion; do $phpversion install xmldiff; doneThis command iterates through PHP versions 7.2 to 8.0 and installs the
xmldiffextension for each available version. Adjust the version range ({72..80}) and extension name as needed.