abhogu
abhogu

Reputation: 403

Libsodium and pecl-libsodium installed but PHP throws error

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.

Upvotes: 3

Views: 2633

Answers (1)

tugelblend
tugelblend

Reputation: 317

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.

Upvotes: 2

Related Questions