Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

PHP prints 'Unable to load dynamic library' every time it starts

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

  • Applies to PHP 8.3, PHP 8.4, Ubuntu 24.04, Windows PHP 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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"
  2. 2Match what you see, then jump to its fix

    1. 1The warning lists the directory it tried, and the file is not in it.extension_dir points to the wrong folderFix
    2. 2The file exists in extension_dir but still cannot load.The file does not match this PHP buildFix
    3. 3You fixed the line but the same warning prints.You edited a php.ini that is not the one loadedFix

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 imagick

Confirmed by php.net

Did this fix it?

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-imagick

3Verify

Restart the web server and look for the extension in phpinfo().

php -m | grep -i imagick

Confirmed by php.net

Did this fix it?

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/null

2Fix

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-fpm

3Verify

Run PHP from the command line and check the output is clean.

php -v

Confirmed by php.net

Did this fix it?

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

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.