The PHP warning unable to load dynamic library occurs when PHP can’t load a required extension.
Most often, this happens when PHP can’t find the extension you defined in your php.ini
file.
For example, the error goes like this:
PHP Warning: PHP Startup: Unable to load dynamic library 'mysqli'
To solve this warning, you need to make sure that PHP is able to find the required extension.
First, find the php.ini
file location by running the phpinfo()
function as follows:
Once you find the php.ini
location, open the file and search for the line that says extension_dir
as shown below:
extension_dir="C:\xampp\php\ext"
The extension_dir
configuration is used to define a folder where your PHP extensions are stored.
Open the extension_dir
using your file explorer and see if the extension that causes the warning exists in that folder.
For example, the mysqli
extension requires the php_mysqli.dll
file (Windows) or php_mysqli.so
(UNIX-like)
When you don’t find the file, then you need to somehow get it from the Internet.
For Windows, you can download the compiled PHP version from windows.php.net and get the extension in ext/
folder in the zip file.
You need to copy the extension from the ext/
folder to your extension_dir
folder.
For UNIX-like OS, you can install PHP extensions with PEAR.
Once you have the extension, restart your PHP server. The warning should now disappear.
If you know that you don’t need the extension, you can comment out the extension to make the warning go away.
Add a semicolon (;
) before the extension configuration as shown below:
;extension=mysqli
Save the changes to the php.ini
file and restart your PHP server. You should no longer see the warning.
Now you’ve learned how to solve the warning PHP Startup: Unable to load dynamic library. Great work! 👍