6

I'm trying to install the libsodium php extension (https://pecl.php.net/package/libsodium/1.0.6/windows).

When I run php -m, libsodium shows up in the list. However, when I go to phpinfo, it is not listed.

I also noticed that apache is giving me the error: PHP Warning: PHP Startup: Unable to load dynamic library 'C:\\xampp\\php\\ext\\php_libsodium.dll' - The specified module could not be found.\r\n in Unknown on line 0

I've checked multiple times and the file is definitely there and matches the correct architecture and thread safety, so I'm at a loss for what else could be causing this.

Any help would be appreciated.

ChrCar627
  • 63
  • 1
  • 1
  • 3
  • looks like you have libsodium activated in the php.ini of your CLI PHP but not in the php.ini used by your Apache Webserver. – LBA Mar 08 '17 at 21:38
  • @LBA Under phpinfo it says `Configuration File (php.ini) Path C:\WINDOWS Loaded Configuration File C:\xampp\php\php.ini` But when I go to the windows directory it doesn't have a php.ini file, so I assume it's loading the one in hte xampp directory listed there, which is the one I've been editing to load the extension. – ChrCar627 Mar 09 '17 at 15:58

3 Answers3

6

In my experience, you can get the 'Unable to load dynamic library' message for a couple of different reasons:

  1. You have enabled a module in php.ini but PHP can't find the dll file (either it doesn't exist, or it is in the wrong directory).
  2. The dll file was compiled for the wrong architecture (32-bit vs 64-bit) or the wrong threading model (e.g. a thread-safe DLL being used on a non-thread-safe version of PHP).
  3. The dll has some dependencies that couldn't be found. For example, you may need some additional .dll files to be put in a location that PHP can find them (e.g. in the main PHP directory).

In your case, given that you indicate a difference between what PHP reports using php -m and phinfo() (presumably in a web page), #1 may be the cause. Extensions are looked for in the location specified by the extension_dir setting in php.ini. If this is a relative path, then it may resolve differently in the context of the web server than it does when running from the command-line.

HappyDog
  • 1,230
  • 1
  • 18
  • 45
  • I checked my extension_dir to make sure it was correct, and it is listed both in the php.ini file and through phpinfo() as "C:\xampp\php\ext". I made sure to follow the instructions listed for libsodium, and placed lib_libsodium.dll inside of that directory. I also put libsodium.dll in "C:\xampp\php", alongside php.exe. – ChrCar627 Mar 09 '17 at 16:01
  • What does ````php -i```` show as the extension dir? Is it different from the command-line? Also, what does ```````` show in each case (web vs. cli)? – HappyDog Mar 09 '17 at 17:40
  • php -i says `extension_dir => C:\xampp\php\ext => C:\xampp\php\ext`, which is the same thing listed on both web and cli. For the getcwd, the cli gives me `C:\xampp`, but the web one gives me my desktop: C:\Users\myusername\Desktop\ – ChrCar627 Mar 09 '17 at 18:29
  • A-hah! I wonder if that could be the problem. Does it work if you put lib_libsodium.dll on your desktop? – HappyDog Mar 09 '17 at 23:16
  • Also, another thing worth checking is what ```````` gives you - is there a difference here? – HappyDog Mar 09 '17 at 23:17
  • Alright, I tried putting the file on the desktop but nothing happened. I also tested the getenv("PATH") but it returned the same value for both of them. Last night I decided to just give up on trying to get xampp to work with the extensions, and I'm instead going to just use an old machine I had lying around to run LAMP, which should be fine for what I need it for. Thanks for all your help though! – ChrCar627 Mar 10 '17 at 14:09
  • Sorry you weren't able to get it working. It's normally resolvable with a bit of patience, but you're right - sometimes it isn't worth it. :-) Glad you've got to some sort of a solution, anyway. – HappyDog Mar 10 '17 at 15:43
  • Looks like the things could break, even when there are some version conflicts between Sodium and php... – Romeo Sierra Mar 30 '20 at 07:03
3

Try copy xampp\php\libsodium.dll to xampp\apache\bin\libsodium.dll and restart apache. On XAMPP 8.0.5 me help.

Ripper
  • 49
  • 2
1

Try to install libsodium:

verify php and pecl php -v pecl version

If you have php7.X then: sudo pecl install -f libsodium

If you are inside a Docker container: pecl install -f libsodium

Add sodium.so extension to php.ini.

sudo echo "extension = sodium.so" > /etc/php/7.1/mods-available/sodium.ini sudo phpenmod sodium

Verify that extension was installed php -i | grep "sodium"