in laravel, php

Setting up Laravel, PHPStorm and Xdebug

You have created and run your Laravel application. Let’s imagine you have discovered that it functions not the way you expected. For example, it returns a wrong value or crashes with an exception. Seems like you have errors in your code, and it’s time to debug it. I’ll walk you through the steps to setup Xdebug in PHPStorm for Laravel application.

Validate Xdebug and PhpStorm settings

  1. Open File -> Settings in PhpStorm
  2. Click on PHP -> Settings (3 dots)
  3. You should be able to see Xdebug version as below.

If you don’t see Xdebug version information, you may need to install and enable xdebug for your php version.

Create new run configuration

Due to the way php artisan serve is designed, we cannot use this command (even with additional arguments) to start server in debug mode. We’ll have to create new run configuration.

  1. Open Run -> Edit Configurations…
  2. Click “+”, choose ‘PHP Built-In Web Server’
  3. Set values as below
    • Name: Appropriately
    • Host:
    • Port: 8000
    • Document root: Select your project’s public/ directory
    • Use router script: Select server.php from project directory.
    • Command Line – Interpreter options: -dxdebug.mode=debug -dxdebug.client_port=9000 -dxdebug.client_host= -dxdebug.start_with_request=1

Start web server and listen for PHP debug connections

  1. Click Menu -> Run -> Run…
  2. Choose the run configuration created in previous step
  3. Server should be up now
  4. Enable PHP debug listener in PhpStorm
  5. Put breakpoints and enjoy debugging.

Make sure “Start Listening for PHP Debug Connections” is enabled while you are debugging. You can click on same button again to disable it. In the screenshot below its enabled (green icon).

Write a Comment