Install custom PHP extension in PHP 7.3

monkey64

Well-Known Member
Nov 6, 2011
124
5
68
cPanel Access Level
Root Administrator
Hi

I am trying to install a custom .so PHP extension in PHP 7.3. The phpinfo() command shows my PHP extension dir to be "/opt/cpanel/ea-php73/root/usr/lib64/php/modules" so I tried adding the maxminddb.so extension there. The GitHub page installation docs said I needed to add the following in the PHP 7.3 ini file:

Code:
extension=maxminddb.so
I restarted PHP-FPM and Apache but my code throws an error because it can't find the class:

Code:
Fatal error: Uncaught Error: Class 'MaxMind\Db\Reader' not found
I was expecting the extension/module to show up in phpinfo() but it doesn't, which rather looks as though it is not being loaded. Am I doing this correctly? Perhaps it is not possible to load custom extensions. Can anyone help?

Thanks
 

monkey64

Well-Known Member
Nov 6, 2011
124
5
68
cPanel Access Level
Root Administrator
EA4 is RPM based but I have other custom PHP ".so" extensions which work in this way.
For example, I have a memcached.so module which is installed in "/opt/cpanel/ea-php72/root/usr/lib64/php/modules". I can prove it works by viewing phpinfo(). I can see "Memcached" show up in the info returned by the function. If I remove the memcached.so module and restart PHP, the Memcached section disappears.

@dalem:
You say "you have to build an RPM for it" but how come my other extensions work?
 
Last edited:

cPanelLauren

Product Owner II
Staff member
Nov 14, 2017
13,266
1,304
363
Houston
You're installing the module but are you inititalizing it? You would need to add a file at:

Code:
/opt/cpanel/ea-php72/root/etc/php.d
in the format of (we'll use mbstring as an example):
Code:
cat 20-mbstring.ini
; Enable mbstring extension module
extension=mbstring.so
I can prove it works by viewing phpinfo(). I can see "Memcached" show up in the info returned by the function. If I remove the memcached.so module and restart PHP, the Memcached section disappears.
Are you using your own version of this or the cPanel provided version available in the experimental repository?

When installed using the experimental repository it is placed in the following:

/opt/cpanel/ea-php72/root/usr/lib64/php/modules/memcached.so
/opt/cpanel/ea-php72/root/etc/php.d/memcached.ini

Now, I don't know if there is any further configuration required for the extension you're installing, which could make a difference and I'd note @ashirjaan's instructions in that case but ultimately the right way to do this is to add the include in the correct directory rather than modify the .ini file directly