3

I need to encrypt passwords and some other data in my PHP(5.5.9) application on Ubuntu (14.04) server. I read about libsodium and found it a good fit for the applications requirements. I followed all the instructions given in the only tutorial available for libsoidum.

  1. sudo add-apt-repository ppa:chris-lea/libsodium - Done, no errors
  2. sudo apt-get update && sudo apt-get install libsodium-dev - Done, no errors
  3. pecl install libsodium - Done, no errors
  4. added extension=libsodium.so to php.ini and restarted apache.

When I check phpinfo() page I am able to see the entry for libsodium as follows:

libsodium support enabled

libsodium compiled version 1.0.6

libsodium headers version 1.0.3

libsodium library version 1.0.3

However, when I try to run the basic example given in the above tutorial which is:

<?php  var_dump([ \Sodium\library_version_major(),\\Sodium\library_version_minor(),\Sodium\version_string() ]);?>

I get an error saying "Call to undefined function Sodium\library_version_major()".

This is really baffling me as the extension is identified correctly by phpinfo() page.

Can anyone please help me in understanding if I am missing something or doing wrong that I am not able to use libsodium with php. Any help is greatly appreciated.

Thank you.

abhogu
  • 393
  • 4
  • 18
  • Did you try `\library_version_minor()` ? Did you check http://php.net/manual/en/function.get-extension-funcs.php – E_p Aug 10 '16 at 16:51
  • I tried your suggestion, still it does not work. Also, I tried get_extension_funcs but it does not print anything. Could this be a problem in some settings with respect to apache2 and dynamic libraries? – abhogu Aug 11 '16 at 16:45
  • If `get_extension_funcs('Sodium')` returns you nothing that might be the problem. Library is not loaded properly – E_p Aug 11 '16 at 17:25
  • Thank you E_p. I will try the entire procedure again. – abhogu Aug 12 '16 at 05:49

1 Answers1

2

I assume that you've tried to run the basic example from the command line. In this case it is necessary to not only add extension=libsodium.so to the php.ini of apache2 that is found at /etc/php5/apache2/php.ini on Ubuntu 14.04.

Additional it is necessary to add this line to the php.ini file for the cli environment found at /etc/php5/cli/php.ini.

tugelblend
  • 197
  • 3
  • 11
  • This insight helped me A LOT. Thanks! And for those who wonder the path, try some version of this: `/etc/php/7.0/fpm/php.ini` – Lucas Serafim May 26 '17 at 00:39