Skip to content

Enabling a PHP extension on a single cPanel account without server-wide impact

How to add a PHP extension to one account on a cPanel server using ea-php package installation plus per-account ini overlay, without making the extension available to every other account.

A customer needs the imap PHP extension for a contact form. Installing it server-wide is one yum command, but then every other account also gets imap loaded into every PHP process — and any future security advisory on the extension applies to every account. The supported pattern under cPanel is: install the RPM, then enable the extension only in the account’s per-user ini overlay.

What’s happening

Each ea-php<ver> PHP build loads extensions from /opt/cpanel/ea-php<ver>/root/etc/php.d/. Files in that directory are loaded for every PHP process under that version. To enable an extension only for one account, you install the RPM (so the .so file is on disk) but you do not enable it in the global php.d/ — instead, you enable it in the per-account ini that PHP reads after the global ones. The per-account ini lets you extension=imap.so for one account; the others never see it loaded.

How to verify

Confirm what is currently enabled where:

ls /opt/cpanel/ea-php82/root/etc/php.d/
rpm -qa | grep "ea-php82-php-"
php -m | head -30
cat /var/cpanel/users/<user>/php.ini 2>/dev/null

The php.d/ directory is the global enable list. The RPM list shows what is installed. php -m shows what is actually loaded for a CLI process under the default version.

The fix

  1. Install the extension RPM: yum install -y ea-php82-php-imap. This places the .so file under /opt/cpanel/ea-php82/root/usr/lib64/php/modules/ and drops an enable file at /opt/cpanel/ea-php82/root/etc/php.d/40-imap.ini.
  2. Disable the global enable: rename 40-imap.ini to 40-imap.ini.disabled (cPanel ignores files not ending in .ini). Now no account loads imap by default.
  3. Edit the per-account ini at /var/cpanel/users/<user>/php.ini (or use MultiPHP INI Editor > Basic Mode and add a custom directive). Append:
    extension=imap.so
  4. Reload the FPM pool for that version: systemctl reload ea-php82-php-fpm.
  5. Validate that the extension is loaded for the target account but not others. From the account’s docroot, place a one-line <?php echo extension_loaded("imap") ? "yes" : "no"; ?> probe and hit it. Then place the same probe in another account and confirm it returns “no”. Delete both immediately.
  6. Document the override. The next operator who sees 40-imap.ini.disabled and reflexively re-enables it will remove the boundary you set.

For environments where extension scope is part of multi-tenant isolation, Stack Harbor records per-account enables against a risk assessment in WHM server management.