phpapachexamppphp-extensionlibsodium

Unable to load dynamic library 'php_libsodium'


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.


Solution

  • 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.