PHP prints 'Unable to load dynamic library' every time it starts
PHP Warning: PHP Startup: Unable to load dynamic library 'imagick' (tried: /usr/lib/php/20230831/imagick ...)Short answer
PHP read an extension line in php.ini and could not open the file. The usual reasons are a wrong extension_dir, an extension built for a different PHP build, or a line in a php.ini you forgot you had. Find the loaded files first, then correct or remove the bad line.
Fix it fast
1Find out which cause you have
List every ini file PHP read. The bad extension line is in one of them.
php --ini php -i | grep -E "extension_dir|Loaded Configuration"2Match what you see, then jump to its fix
- 1
The warning lists the directory it tried, and the file is not in it.extension_dir points to the wrong folderFix - 2
The file exists in extension_dir but still cannot load.The file does not match this PHP buildFix - 3
You fixed the line but the same warning prints.You edited a php.ini that is not the one loadedFix
- 1
What does the error look like?
PHP Warning: PHP Startup: Unable to load dynamic library 'imagick' (tried: /usr/lib/php/20230831/imagick ...)Warning: PHP Startup: Unable to load dynamic library 'php_curl.dll'
Cause 1 of 3
extension_dir points to the wrong folder
1Check
extension_dir tells PHP where to look for extension files, and an absolute path is recommended. A relative path or one left from another install breaks.
php -r "echo ini_get('extension_dir'), PHP_EOL;"
ls "$(php -r "echo ini_get('extension_dir');")"2Fix
Set it to the folder that really holds the extension file.
; php.ini
extension_dir = "/usr/lib/php/20230831"
; Windows:
; extension_dir = "C:\PHP\ext"3Verify
Start PHP again; the warning must be gone and the extension listed.
php -m | grep -i imagickConfirmed by php.net
Cause 2 of 3
The file does not match this PHP build
1Check
A Windows DLL has to match the PHP version, thread safety, architecture (x86 or x64) and debug setting. A needed second DLL missing next to it fails in the same way.
php -i | findstr /i "Thread Architecture Debug"
# Linux: php -i | grep -iE "thread safety|architecture|debug build"2Fix
Download or install the extension built for exactly this PHP, or use your package manager's package for the same version.
sudo apt install php8.3-imagick3Verify
Restart the web server and look for the extension in phpinfo().
php -m | grep -i imagickConfirmed by php.net
Cause 3 of 3
You edited a php.ini that is not the one loaded
1Check
PHP uses an explicit path first, then PHPRC, the working directory (not for CLI), the binary's folder and the compiled default. CLI and web SAPIs may read different files, and extra .ini files in the scan directory are read too.
php --ini
grep -rn "imagick" /etc/php/ 2>/dev/null2Fix
Remove or correct the extension line in the file that actually contains it, then restart the web server or PHP-FPM so the change is read.
sudo systemctl restart php8.3-fpm3Verify
Run PHP from the command line and check the output is clean.
php -vConfirmed by php.net
How do I stop it coming back?
- Use the extension name (extension=imagick) instead of a file name, which PHP supports since 7.2.
- Install extensions through the package that matches your exact PHP version.
- After a PHP upgrade, rerun php --ini and check for leftover lines from the old version.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache returns 503 or 504 because PHP-FPM did not answer in time
Error dispatching request
Apache sent the request to PHP-FPM and gave up waiting.
3 causes, each with a fixBack end
AWS SDK for PHP cannot get credentials from the instance profile metadata server
Error retrieving credentials from the instance profile metadata server.
The SDK tries the EC2 instance metadata service when it has no valid credentials from anywhere earlier in its chain.
4 causes, each with a fixBack end
AWS SDK for PHP rejects requests: the signature is from the future
Signature not yet current: {date} is still later than {date}
AWS compares the timestamp in your signed request with its own clock.
2 causes, each with a fixBack end
CodeIgniter 4 cannot write its cache files
CodeIgniter\Cache\Exceptions\CacheException: Cache unable to write to /var/www/app/writable/cache/
CodeIgniter 4's file cache needs a cache directory that the web server can really write to.
2 causes, each with a fixBack end
CodeIgniter 3 loads the model but the property is undefined
The model name you are loading is the name of a resource that is already being used: user
CodeIgniter 3 expects a model file named like its class, with the first letter capitalised, for example User_model.php holding class User_model.
2 causes, each with a fixBack end
CodeIgniter 3 stops with "Your system folder path does not appear to be set correctly"
503 Service Unavailable
CodeIgniter 3's front controller resolves $system_path and then checks that the result is a directory.
3 causes, each with a fix