PhpStorm xdebug can't find file when connection comes from docker container

12,928

Solution 1

The same issue applies, when trying to debug on PHPStorm with docker.

You can resolve it by adding a server_name to the nginx config :

The server_name _; should get set to _, which is the default server name. You can also add another server name, resulting in PhpStorm adding a new PHP Server (Settings: PHP > Servers) and will use this as the Name: server_name _ MyProject;

server {
    listen 80;
    ### Add the following line to nginx config file ###
    server_name  _  AnotherServerNameForPhpStorm;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/public;
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app_bug:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include xdebug/remote.conf;
    }
    location / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }
}

Hope this helps someone still has the same problem with me

Solution 2

I usually set the docker subnet IP as a remote host ip like this:

XDEBUG_CONFIG=remote_host=172.17.0.1
PHP_IDE_CONFIG=serverName=your_server_name_in_phpstorm_settings

You could check ip in Linux with this command:

ifconfig docker0

Also if you're using docker-compose you could move xdebug variables definitions to a separate .env file and link it to the container config in docker-compose.yml:

container_name:
    ...
    env_file: .env
    ...
...

Solution 3

I faced with same problem Try to add in xdebug config this line:

xdebug.extended_info = 1

it should to pass env variable to $_SERVER

Solution 4

Try to add this way:

environment:
  PHP_IDE_CONFIG: "serverName=Magetwo"

Then in Settings > PHP > Servers add a new server with name Magetwoand the host and port you're using to debug. enter image description here

Share:
12,928

Related videos on Youtube

Rudolf
Author by

Rudolf

Updated on September 20, 2022

Comments

  • Rudolf
    Rudolf over 1 year

    I'm trying to move my Magento development environment to docker. I've started with this ready to use solution. Almost everything works properly except xdebug.

    I've set up PhpStorm according to this tutorial and I have properly mapped my local project directory on docker volume in the server section. When I try to start debugging then appears in debugger window this message

    Cannot find file '/var/www/html/pub/index.php' locally. To fix it set server name by environment variable PHP_IDE_CONFIG and restart debug session.

    I've added this

    environment:
      - PHP_IDE_CONFIG=serverName=Magetwo
    

    to the docker-compose.yml in the php section, but still the same error. Debugging works only when I have project located in the same directory on the host like in the container volume, but I want to have different directory.

    What should I change to force xdebug to work?