Setup Xdebug on PhpStorm with Homestead
Xdebug is an extension for PHP to assist with debugging and development.
It provides a slightly better DX than doing a DD
, VAR_DUMP
or PRINT_R
on php when you’re
trying to inspect something.
-
SSH into your homestead machine (
vagrant ssh
). -
Run this command to enable xdebug
sudo phpenmod xdebug
-
Install browser debugging extension on your primary browser, Here are links
-
Map PHP Interpreter in phpstorm.
- In phpstorm press
ctrl + alt + s
- Select
Languages & Frameworks > PHP > CLI Interpreter
- Click on + button & type your vagrant/homestead server details.
- In General, Set PHP executable to:
/usr/bin/php
- In phpstorm press
-
Setup path mappings
- In phpstorm press
ctrl + alt + s
- Select
Languages & Frameworks > PHP > Servers
- Click on
+
button. - Enter host, post, debugger (=Xdebug from the drop down)
- Tick
Use path mappings
- Set the corresponding project for local directory to absolute path on server.
Eg:
D:\sites\flipkart
to/home/vagrant/flipkart
- In phpstorm press
-
Now, open your Laravel project in PHPStorm. Open
web.php
& go to the controller that handles/
(root) of your project. (eg:HomeController@index
) On the line that returns view or JSON, pressctrl + f8
to add debugging breakpoint. Note: This is important step, Without doing this the Xdebuger will finish execution without any output. -
Go to your browser, And open the project’s
/
or root url for which you set up the breakpoint (eg: flipkart.local)
Xdebug causes PHP to run significantly slower. To disable Xdebug, run sudo phpdismod xdebug
within your Homestead virtual machine
and restart the FPM service.
Here are some useful links if you get stuck
Set Up xDebug, with Homestead, PHPStorm and PHP7
Remote file path is not mapped to any file path in project
Debugging Web Requests With Xdebug
Debugging: Configure Xdebug + Laravel Homestead + VS Code + PHPUnit