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

MisstypingMeerkat's avatar

Setting up XDebug on Docker, PHPStorm and my Laravel app?

Hi there,

I am trying to xdebug my laravel app inside docker with PHPStorm, but I can’t seem to get it working.

I have done this setup before without docker where my web server runs on the host os and never had much trouble with it, but in the current setup I’m pretty confused. When I set PHP to “Break at first line in PHP scripts” it would sometimes stop while I was trying different configuration changes, but only to stop in server.php or 2 other system files, but NOT in my controllers or models where I set my own breakpoints.

Here is what my setup looks like:

MacOS

Docker

  • laravel_app (plus DB, Mailserver etc.)

Laravel_app inside docker consists of 2 parts, the frontend build with next.js, and the laravel-api which is the php backend I would like to debug. The api calls are made to https://laravel-api.local .The app is all set up and running, except for xdebug. I tried at least 5 different tutorials and step-by-step guides online, but none of them worked.

My own uneducated guess is that it either has something to do with some path mappings in PHP storm, or PHPstorm or xdebug won’t listen for laravel-api.local where my api endpoints are served and never know when a breakpoint is reached.

Here are my config files:

docker-compose.yml

version: '3'
services:
proxy:
image: nginx
    ports:
        - 80:80
        - 443:443
    volumes:
        - ./proxy/conf/nginx.conf:/etc/nginx/nginx.conf
        - ./proxy/certs:/etc/nginx/certs
    depends_on:
        - laravel.test
    networks:
        - sail
laravel.test:
    build:
        context: ./vendor/laravel/sail/runtimes/8.1
        dockerfile: Dockerfile
        args:
            WWWGROUP: '${WWWGROUP}'
    image: sail-8.1/app
    extra_hosts:
        - 'host.docker.internal:host-gateway'
    ports:
        - '8002:8002'
    environment:
        WWWUSER: '${WWWUSER}'
        LARAVEL_SAIL: 1
        XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-debug,develop}'
        XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
    volumes:
        - '.:/var/www/html'
    networks:
        - sail
    depends_on:
        - mysql
        - redis
        - meilisearch
        - selenium`
(Other containers here…)

xdebug section in phpinfo() / php.ini, all defaults except xdebug.client_host:

xdebug.client_host : host.docker.internal
xdebug.client_port : 9003`

/etc/hosts inside docker laravel container, see last line:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section 

# added for xdebug
127.0.0.1       host-gateway

/etc/hosts in host os, see last line:

# Host Database

#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
# Added by Docker Desktop
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
127.0.0.1       host-gateway

I did not set up anything in PHPStorm->Run Configurations->Remote Debug because there was no relevant setting as far as I could tell.

Does anyone have an idea what is wrong here? Where would I have to enter my api endpoints hostname https://laravel-api.local so xdebug will listening to it?

Do I have have to make any special settings so it will also pick up connections via https/port 443?

Any help would be appreciated.

0 likes
1 reply
benmag's avatar

I've had this exact same problem too and finally figured it out... I think it is to do with the path mappings

What worked for me was to go to Preferences > PHP > Servers. Then under Project Files set the "Absolute Path on the Server" to /var/www/html then click OK

Then make sure "Break at first line in PHP scripts" is unchecked (under PHP > Debug)

Refresh the page (with Debug enabled) and it should now be paused on your actual breakpoint

Please or to participate in this conversation.