How to debug a Yii2 project with XDebug and PHPStorm IDE

What’s up, guys! Today we are talking about debugging and a debugger. First of all I have to notice you that this article for beginners wants to have an ability to debug their own Yii2 project in powerful IDE PHPStorm with XDebug.

Get started. In my case I used next instruments:

  1. Apache 2.4
  2. PHP 5.5
  3. Chrome browser with JetBrains IDE Plugin 2.8
  4. PHPStorm 9
  5. xDebug 2.2.6

Step 1. In your php.ini find a section [Xdebug] and uncomment directives below:

zend_extension=”YOUR_PATH_TO_PHP/ext/php_xdebug.dll” xdebug.default_enable = 1 
xdebug.remote_autostart = 0
xdebug.remote_enable = 1
xdebug.remote_port = 9001

After that you should check out your php configuration through phpinfo() function. If you can find xdebug in properties list this mean you have configured the xDebug right.

Output of a phpinfo()

Step 2. Go to PHPStorm->File->Settings->Language & Frameworks

You should set up development environmental in php-interpretation part some like this:

Interpreter settings

Step 3. Then go to PHPStorm->File->Settings->Language & Frameworks->PHP->Server and set up your webserver’s options:

Local webserver settings

Step 4. In PHPStorm->File->Settings->Language & Frameworks->PHP->Debug configure xDebug settings:

Debugger settings

Step 5. In top right corner of the PHPStorm select “Edit Configurations…” option

Run&Debug toolbar

Step 6. In appeared window click on “+” and add “PHP Web Application”.

Project’s Run&Debug options

That’s all. Next step is set breakpoints by clicking on left side of an editor against some functions or other entities that you want to explore.

Click on a bug icon in top panel

Result may looks like on an image below:

PHPStorm 9 main window

Thanks for reading!

Show your support

Clapping shows how much you appreciated Evgeniy Poremchuk’s story.