Unable to load dynamic library imagick.so

I tested my website on my development machine fine, but have an error below when being deployed on a shared server:

2015-10-27 08:00:10 [][-][2d12367f735ce12cdfeba82a431366ad][error][yii\base\ErrorException:32] exception ‘yii\base\ErrorException’ with message ‘PHP Startup: Unable to load dynamic library ‘/usr/local/lib/php/extensions/no-debug-non-zts-20100525/imagick.so’ - libMagickWand.so.2: cannot open shared object file: No such file or directory’ in Unknown:0

Stack trace:

#0 [internal function]: yii\base\ErrorHandler->handleFatalError()

#1 {main}

2015-10-27 08:00:10 [][-][2d12367f735ce12cdfeba82a431366ad][info][application] $_COOKIE = [

'PHPSESSID' => '2d12367f735ce12cdfeba82a431366ad'  

'_csrf' => '9182966bd3d019ee8171015606c88e3220259f0c834dcf1ae03902ce58f66d79a:2:{i:0;s:5:\"_csrf\";i:1;s:32:\"nRH7m_XI2w0uOW2AQgRp06xQ6fPeNWnw\";}'  


I ran the requirements.php and it passed, the server side support engineer also confirmed that imagick.so exists in the path shown above.

The engineer is struggling to identify the problem.

Does anyone had similar probelm before?

This error occurs on every page of my website, eventhough most pages are not Captcha.

The pages are rendered, and then at the bottom of the page this error turns up.

Could anyone point to me the code that is causing this error? It seems to be the yii2 core, but why on pages that do not use Captcha still get this error?

Also is there a way in YII2 to ask Captcha to try using GD first instead Imagick? I am asking this because my gut feeling is the Imagick extension has problem.

Many thanks.

I don’t know if its the best solution, but to force GD you can extend \yii\captcha\CaptchaAction class and override renderImage () method. Something like this:


namespace app\components;

class CaptchaAction extends \yii\captcha\CaptchaAction


    protected function renderImage($code)


        return $this->renderImageByGD($code);



Then in controller:

    public function actions()


        return [

            'error' => [

                'class' => 'yii\web\ErrorAction',


            'captcha' => [

                'class' => 'app\components\CaptchaAction',

                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,




Thanks for the solution, I will try and see if it works.

What puzzles me is that even pages not using Captcha get this error (actually on every page), so it seems to me a code down in Yii2 core is trying to use Imagick but failed (not only load the extension, because the requirements.php ran successfully, which does load Imagick).

Unfortunately I am not an expert in Yii2, and can’t get much info from the stack trace.

It seems to be an Imagick installation problem. Yii2 core doesn’t use Imagick.

Take a look at this thread. Maybe it isn’t the solution for your case but is the same problem.

You don’t see the same error on requirements.php because it not loads Yii2, so the framework error handler is not set and this warning is not shown. But probably appears in php error log.