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

  1. 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/pecl

    Replace the version number (72, 73, etc.) with your target PHP version.

  2. Step 2: Install an extension for a single PHP version

    Use the pecl install command with the full path to the PECL binary. For example, to install the xmldiff extension for PHP 7.3:

    /opt/cpanel/ea-php73/root/usr/bin/pecl install xmldiff
  3. 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; done

    This command iterates through PHP versions 7.2 to 8.0 and installs the xmldiff extension for each available version. Adjust the version range ({72..80}) and extension name as needed.