How to configure Xdebug for Laravel in PHPSTORM

Laravel

How to configure Xdebug for Laravel in PHPSTORM

No one should ever underestimate the importance of a fully set up development environment and none is complete unless you have proper error debugging tools in place.

Xdebug will help us discover the source of the problems in our code and give us a better insight on what is happening.

This article will cover how to configure xdebug with xampp on Windows.

We will use official xdebug tailored installation on this website https://xdebug.org/wizard.php. What we have to is to paste either the output of phpinfo() or php -i from the terminal. You can choose whichever option is easier for you. I will use php -i from the command line terminal.

Once you get the output copy it into the text area on the website and click analyze. When it finishes it will give you an appropriate version of xdebug to download and provide you with the instructions of where to put it.

For me:

  1. Download php_xdebug-2.7.2-7.3-vc15.dll
  2. Move the downloaded file to C:\xampp\php\ext
  3. Update C:\xampp\php\php.ini and change the line zend_extension = C:\xampp\php\ext\php_xdebug-2.7.2-7.3-vc15.dll

 

After I copied xdebug dll to its proper place I added the following configuration to the php.ini file at the same location as instructed in the third step above.

[xdebug]
zend_extension = C:\xampp\php\ext\php_xdebug-2.7.2-7.3-vc15.dll
xdebug.remote_autostart=1
xdebug.default_enable=1
xdebug.remote_port=9001
xdebug.remote_host=127.0.0.1
xdebug.remote_connect_back=1
xdebug.remote_enable=1
xdebug.idekey=PHPSTORM

 

Now we need to restart apache service in order for it to use new configuration.

Xampp control panel

That part is finished. Now, let's configure PHPSTORM.

 

In the top right corner click on add configuration.

PHPSTORM configuration

 

Click on the plus icon and select PHP Web Page.

PHPSTORM web page

 

Enter the name and click on the button with three dots.

PHPSTORM server configuration

 

Here we specify the 127.0.0.1 domain and 8000 port on which Laravel serves.

PHPSTORM server configuration

 

Hit apply and close the modal.

PHPSTORM server configuration

 

Now open settings (File -> Settings) and change the Xdebug settings as follows.

PHPSTORM Xdebug settings

 

Then under DBGp Proxy as ide key set PHPSTORM and port to 9001 to match the settings we added in php.ini. Hit apply and now we are ready to test our code.

PHPSTORM Xdebug proxy settings

 

Let’s put a breakpoint somewhere in our code to see if it actually works.

PHPSTORM Xdebug breakpoint

Here we can see that our code stoped executing on the breakpoint and that we have an option to inspect the variables we have.

That’s awesome. Although simple with instructions, installing and configuring Xdebug on your own can be a pain. However, it’s quite worth it when you see how easy it is to debug your code with it.

Show comments

Laravel

5 min

How to make Laravel authentication

Laravel provides a neat function that quickly generates a scaffold of routes, views, and controllers used for authentication.

Laravel

7 min

How to install Laravel application

This article will cover how to install and create a local development environment for your Laravel application. There are only a couple of steps that needs to be done.

Laravel

3 min

How to set appropriate Laravel permissions on Linux server

After publishing your Laravel application to a real web server, you discover then some of your functionalities are failing.

Codinary