Adding libsodium to PHP 7.2 and 7.3 on a cPanel server

If you are on a server with WHM/cPanel, you may notice that they don’t include sodium in the list of available PHP modules for PHP 7.2 and 7.3, then this guide will help you get around it.

You can try adding the ea4 experimental repo:

yum install ea4-experimental
yum install libsodium-devel

But I haven’t seen that actually work, so to install it from source, ssh in to the server as the root user, or a user that has sudo permissions and run:

cd /usr/src/
tar -zxvf libsodium-1.0.18.tar.gz 
cd libsodium*

make && make check
make install
make check

If that completes successfully, try to install the actual PHP modules now:

/opt/cpanel/ea-php72/root/usr/bin/pecl install libsodium
/opt/cpanel/ea-php73/root/usr/bin/pecl install libsodium

If you try those and get an error like:

Warning: popen() has been disabled for security reasons in PEAR/Builder.php on line 465
ERROR: failed to run `phpize'

Then you may need to go into the MultiPHP INI Editor in WHM,

go to the “Editor Mode” tab, choose the php version from the dropdown list, click in the large text box that shows up, press Ctrl+F to search for “disable_functions” and see if that has popen listed there. If so, remove that and save the file, then if you need to change it for any other php versions as well, switch to those on the drop down list. After that, try running those pecl install libsodium commands again.

If you don’t see popen there, then you may need to talk to your webhost to get that allowed or if the module can be added in a different way.

To confirm it’s added, check the modules using a phpinfo page or use:

/opt/cpanel/ea-php72/root/usr/bin/php -m | grep sodium

/opt/cpanel/ea-php73/root/usr/bin/php -m | grep sodium

Additional Keywords: lib_sodium, lib-sodium, encryption

Add Comment