NoLAstNamE's avatar

Xdebug not working when in Laravel Valet

This is my first time using Xdebug and I'm setting it up on my Macbook Pro.

I have successfully installed Xdebug and have this on my php.ini

[xdebug]
xdebug.mode = debug
xdebug.client_host = localhost
xdebug.client_port = 9003
xdebug.discover_client_host = true
xdebug.start_with_request = yes

I'm trying the step debugger, it works fine in php artisan serve but when I try to access it via valet's example.test, the step debugger is not triggered.

Has anyone encountered this issue before?

0 likes
2 replies
LaryAI's avatar
LaryAI
AI
Best Answer
Level 58

It sounds like you've got Xdebug installed and configured correctly for CLI usage, but when using Laravel Valet, the debugger isn't being triggered. Here are a few steps you can take to troubleshoot and resolve the issue:

  1. Ensure Xdebug is Loaded for PHP-FPM: Laravel Valet uses PHP-FPM, so you need to make sure that Xdebug is enabled for PHP-FPM as well. You can check this by creating a phpinfo.php file with the following content and visiting it through Valet (e.g., http://example.test/phpinfo.php):

    <?php phpinfo(); ?>
    

    Look for the Xdebug section to confirm it's being loaded.

  2. Configure Xdebug for PHP-FPM: If Xdebug isn't loaded, you'll need to ensure that the php.ini file used by PHP-FPM has the Xdebug configuration. The php.ini file for PHP-FPM might be different from the CLI php.ini. You can find out which php.ini file is being used by PHP-FPM by looking at the output of phpinfo() under the "Loaded Configuration File" section.

  3. Restart Valet: After making changes to the php.ini file, you need to restart Valet to apply the changes. You can do this by running:

    valet restart
    
  4. Check Firewall Settings: Ensure that your firewall is not blocking the port that Xdebug is trying to use (default is 9003). You might need to add a rule to allow traffic on that port.

  5. IDE Configuration: Make sure your IDE is listening for Xdebug connections on the correct port (9003). You should also verify that the IDE key (if used) matches the one configured for Xdebug.

  6. Path Mapping: If you're using a remote interpreter setup in your IDE, ensure that the path mappings are correctly configured. The server's root path should map to your local project's root path.

  7. Check Xdebug Log: You can enable Xdebug's log to get more information about what's happening. Add the following line to your Xdebug configuration:

    xdebug.log = /tmp/xdebug.log
    

    After trying to trigger the debugger, check the /tmp/xdebug.log file for any errors or clues.

  8. Use Xdebug Helper Browser Extension: If you're using a browser, you can install an Xdebug helper extension that allows you to easily toggle debugging, profiling, and tracing. Make sure it's configured to use the correct IDE key.

If after following these steps Xdebug is still not triggering when using Valet, you may want to check the Laracasts forums or the Valet GitHub issues for any similar problems reported by other users. It's possible that there might be a specific issue with your setup or a bug that others have encountered and resolved.

NoLAstNamE's avatar

Lary is right, this solved my problem

Restart Valet: After making changes to the php.ini file, you need to restart Valet to apply the changes. You can do this by running:

valet restart

Please or to participate in this conversation.