How to add captcha in Yii-2 application?
<p>I'm trying to add the captcha to the login form.</p>
<p>My environment:</p>
<ul>
<li>Yii 2</li>
<li>php 5.4.45 TS</li>
<li>IIS 10.0</li>
<li>Windows 10</li>
</ul>
<p>In <code>login.php</code>, <code>LoginForm.php</code> and <code>SiteController.php</code> I added the following (shown only the relevant parts):</p>
<p>backend\views\site\login.php:</p>
<pre><code>use yii\captcha\Captcha;
...
&lt;?= $form-&gt;field($model, 'captcha')-&gt;widget(Captcha::className()) ?&gt;
...
</code></pre>
<p>common\models\LoginForm.php:</p>
<pre><code>...
public $captcha;
...
public function rules()
{
    return [
        ... 
        [['username', 'password', 'captcha'], 'required'],           
        ['captcha', 'captcha'],
    ];
}
</code></pre>
<p>backend\controllers\SiteController.php:</p>
<pre><code>public function actions()
{
    return [
        ...
        'captcha' =&gt; [
            'class' =&gt; 'yii\captcha\CaptchaAction',
//                'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null,
        ],
    ];
}
</code></pre>
<p>I have downloaded and installed <a href="https://www.imagemagick.org/script/download.php" rel="nofollow noreferrer">ImageMagick-7.0.2-Q16</a></p>
<p>As described <a href="https://pecl.php.net/package/imagick/3.4.1/windows" rel="nofollow noreferrer">here</a> I have downloaded php_imagick-3.4.1-5.4-ts-vc9-x86.zip and extract php_imagick.dll from there. Then added php_imagick.dll in <code>/php/ext/</code></p>
<p>In <code>php.ini</code> I added the following:</p>
<pre><code>...
[PHP_IMAGICK]
extension=php_imagick.dll
...
</code></pre>
<p>Then restart IIS, but captcha is not displayed and I see the following in the logs:</p>
<pre><code>2016-08-10 07:28:21 [127.0.0.1][-][h1a65krn8scqc9auk56flmesi6][error][yii\base\InvalidConfigException] exception 'yii\base\InvalidConfigException' with message 'Either GD PHP extension with FreeType support or ImageMagick PHP extension with PNG support is required.' in C:\projects\aisnew\vendor\yiisoft\yii2\captcha\Captcha.php:180
</code></pre>
<p>After restarting the operating system:</p>
<pre><code>2016-08-10 07:01:22 [127.0.0.1][-][h1a65krn8scqc9auk56flmesi6][error][yii\base\ErrorException:32] exception 'yii\base\ErrorException' with message 'PHP Startup: ' in Unknown:0
</code></pre>
<p>I read somewhere that the most recent version is working on Windows 10 but need to install the Visual C++ 2013 Redistributable Package. I checked that this package is installed.</p>
<p>How to add captcha in Yii-2 application? I tried different combinations of the ImageMagick and php_imagick.dll, but nothing is working.</p>