Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Cvetan's avatar
Level 6

Laravel Sail XDebug and PhpStorm can't make it work anyhow

I tried with default configuration, I tried adding only this in SAIL_XDEBUG_MODE=debug,develop. Per some instructions found on Internet I also tried adding this SAIL_XDEBUG_CONFIG="client_host=host.docker.internal idekey=PHPSTORM" however when I add that server becomes completely unfunctional and doesn't work. I tried without adding anything in .env, so default configuration that doesn't work as well.

I am interested in listening for debug connections from PhpStorm just to be clear. When I validate debugger from inside IDE(with phpinfo option), I get the following is not configured:

  • remote debug is not enabled
  • discover client host is: OFF

Also I think that SAIL_XDEBUG_CONFIG variable does not do anything, because theoretically I could pass this config keys into it.

0 likes
9 replies
LaryAI's avatar
Level 58

To set up XDebug with Laravel Sail and PhpStorm, you need to ensure that your Docker container is properly configured to communicate with PhpStorm. Here’s a step-by-step guide to help you get it working:

  1. Update your .env file: Add the following lines to your .env file to enable XDebug in Laravel Sail:

    SAIL_XDEBUG_MODE=debug,develop
    SAIL_XDEBUG_CONFIG="client_host=host.docker.internal"
    
  2. Rebuild your Sail containers: After updating the .env file, you need to rebuild your Sail containers to apply the changes:

    ./vendor/bin/sail down
    ./vendor/bin/sail build --no-cache
    ./vendor/bin/sail up -d
    
  3. Configure PhpStorm:

    • Open PhpStorm and go to Preferences > Languages & Frameworks > PHP > Debug.
    • Set the Debug port to 9003 (default for XDebug 3).
    • Ensure that Can accept external connections is checked.
  4. Set up a PHP Remote Debug Configuration:

    • Go to Run > Edit Configurations.
    • Click the + icon and select PHP Remote Debug.
    • Name your configuration (e.g., Sail Debug).
    • Set the Server to the one you configured earlier or create a new one:
      • Click the ... next to the Server dropdown.
      • Click the + icon to add a new server.
      • Name the server (e.g., Sail).
      • Set the Host to localhost.
      • Set the Port to 80 (or the port your Sail application is running on).
      • Set the Debugger to Xdebug.
      • Click OK to save the server configuration.
    • Set the IDE key to PHPSTORM.
  5. Set up path mappings:

    • In the same PHP Remote Debug configuration, click on Path mappings.
    • Map the project root to /var/www/html (the default web root in the Sail container).
  6. Start listening for debug connections:

    • In PhpStorm, click the Start Listening for PHP Debug Connections button (the phone icon in the top right).
  7. Set a breakpoint:

    • Open a PHP file in your project and set a breakpoint by clicking in the left margin next to the line number.
  8. Trigger the debugger:

    • Make a request to your application that will hit the breakpoint you set.

If everything is configured correctly, PhpStorm should stop at the breakpoint, allowing you to debug your application.

Here’s a summary of the key configurations:

.env file:

SAIL_XDEBUG_MODE=debug,develop
SAIL_XDEBUG_CONFIG="client_host=host.docker.internal"

PhpStorm Debug Configuration:

  • Debug port: 9003
  • Server host: localhost
  • Server port: 80
  • Path mappings: Project root -> /var/www/html

By following these steps, you should be able to get XDebug working with Laravel Sail and PhpStorm. If you encounter any issues, double-check each configuration step and ensure that your Docker containers are properly rebuilt.

1 like
aylara's avatar

Had the same problem and abandoned it 3 months ago. @cvetan : did Lary AI's suggestion work?

Cvetan's avatar
Level 6

No it didn't. Larry's suggestions are pretty generic, which you can find by plain google search. :D

As I said these options don't work at all. Even environment variable options seem not to work. I really havet to ask what kind of development environment is there in sail if you can't do such basic thing as easy or debugging at all?

zheliazkov's avatar

@cvetan @aylara just try keeping only SAIL_XDEBUG_MODE=develop,debug,coverage in your .env, delete your Servers (PHPStorm -> Settings -> PHP -> Servers), check that in Settings -> PHP -> Debug under section Xdebug Can accept external connections is checked, turn on Start listening for PHP Debug connections.

Get a browser debugging extension like Xdebug helper for Chrome, install it and go to a project page like localhost.

Enable the debugging from the Xdebug helper (should be green colored) and reload the page - it will automatically open a new dialog in your IDE to create a Server - just create it.

Now your Xdebug will be working while browsing but you need to map the local project files path to the absolute container one (/var/www/html) in your server in Settings -> PHP -> Servers. Example: /Users/Plamen/PhpstormProjects/project-name to /var/www/html.

Put a breakpoint and test it.

If you want to start debugging session while running artisan commands you can use debug command instead of artisan.

Seems that the Jetbrains Zero-configuration debugging is working but there is need of such plugin and the 0.0.0.0 server host.

Hope it helps :)

magicjoef's avatar

I'd be really keen to hear if you got this working. Slightly different case as I'm working with VS Code but, in my .env I have:

SAIL_XDEBUG_MODE=develop,debug,coverage

And in the docker-compose I have:

XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-on}' XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'

I have VSCode set up with launch.json but I don't hit any breakpoints. I did a simple LAMP stack in docker as a comparison and did get that working with Xdebug

magicjoef's avatar

I decided to try a new clean start and set up a new sail app. This time I have had success getting Xdebug working. I added these to .env

SAIL_XDEBUG_MODE=develop,debug

SAIL_XDEBUG_CONFIG="client_host=host.docker.internal idekey=VSCODE"

And this is the launch.json

{ "version": "0.2.0", "configurations": [ { "name": "Listen for Xdebug", "type": "php", "request": "launch", "port": 9003, "pathMappings": { "/var/www/html": "${workspaceFolder}" }, "hostname": "localhost" } ] }

Hope that helps someone.

aylara's avatar

I fumbled till I got it to work some time ago but could not later, for the life of me, replicate what I did.

Just came across this well-written article and applied it to a freshly installed Sail-based Laravel on Windows WSL2. It worked perfectly on first attempt, no issues at all.

imqqmi's avatar

I had a lot of issues getting this working properly as well with laravel 11 sail and phpstorm. In the end I've figured out that phpstorm 2024.2.3 has an issue with the env settings of xdebug in the docker-compose file when adding an interpreter using docker-compose option, as the phpstorm search for the binary stops responding entirely. Removing those xdebug env variables from docker-compose means that you have to change the dockerfile (sail artisan sail:publish will put those in a docker folder). Add this directly below the other RUN group that installs php and dependencies. Replace the 8.3 with the version you're using. This will add xdebug 3 config to the cli php.ini file.

RUN echo "[XDebug]" > /etc/php/8.3/cli/php.ini
&& echo "xdebug.mode = debug" >> /etc/php/8.3/cli/php.ini
&& echo "xdebug.discover_client_host = true" >> /etc/php/8.3/cli/php.ini
&& echo "xdebug.client_host = host.docker.internal" >> /etc/php/8.3/cli/php.ini
&& echo "xdebug.client_port = 9003" >> /etc/php/8.3/cli/php.ini

Rebuild with sail build (--no-cache if you run into issues)

Now php will find the interpreter without freezing and you can setup a server that receives the xdebug calls. It's important that you set the lifecycle to 'Connect to existing container' when adding the interpreter using docker-compose option.

Setting up servers: I have one 0.0.0.0 with mapping to /var/www/html and one localhost to the same folder /var/www/html. Why you need two? Because php serve/browser triggered launches in a different context compared to cli launched php files and tests.

Another issue is where you've got your 'local files' located. For some reason when I map a network drive to \wsl$ phpstorm gets into all kinds of issues trying to map docker to local files.

After a lot of trial and error I've found out the best way to setup phpstorm is to place your local files in \wsl$\home<username> and in a foldere there wherever you like. This is for windows obviously.

Then go in explorer to \wsl$\home<username> and drag the laravel project folder onto the phpstorm icon on your desktop. This will open the folder inside phpstorm using UNC paths which it blocks when you use the normal way of setting up the development environment.

This will correctly map your 'local' files in wsl to the docker files when triggering a xdebug event. This also works with CLI started php files (ie right clicking>run or debug in phpstorm project files tree) and PHPUnit and Pest.

I've made a dockerfile that includes apache instead of php serve, and there was more config work to be done to get xdebug working from browser, cli and unit tests. Only issue that I have is that sail artisan also triggers the debugger which is a bit annoying. I need to turn off debugging in phpstorm to get stop it from triggering temporarily.

stoic-mortal's avatar

I also had the same issue and after a day I managed to solve it. My solution was to add this to docker-compose.yml:

XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-debug}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'

Then in PHP storm I added a server 0.0.0.0 instead of localhost (as some before suggested) and added the mappings to /var/www/html.

I didn't add anything to .env or to the Dockerfile (well I did when I was trying out stuff but in the end that was not the problem).

I am running the latest PHP Storm (2024.2.4) on Sonoma macOS.

P.S.: What you must NOT do is to map the port 9003 to 9003, which was a suggestion by ChatGPT. So that means to NOT have this line in docker-compose.yml

ports:
    - '9003:9003'

Please or to participate in this conversation.