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?
Given that, you can confirm that xDebug is installed and in place by trying the following: 1) phpinfo() -- this will show you all the extensions that are loaded, including xDebug. If it is there, then it's a safe bet that it's working.
When Xdebug is running, it will call back to your IDE (like PhpStorm or VS Code) from the server where it's running. Your IDE will sit and listen for that connection on a specific port (typically port 9000 or 9003).
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
...
...
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
Try to add this way:
environment:
PHP_IDE_CONFIG: "serverName=Magetwo"
Then in Settings > PHP > Servers add a new server with name Magetwo
and the host and port you're using to debug.
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
I had a similar problem, same 'To fix it set server name by environment variable PHP_IDE_CONFIG and restart debug session.'
What solved it for me ultimately was having $_ENV['PHP_IDE_CONFIG'] set. Check your $_ENV when you get this message, I bet you won't have a key called 'PHP_IDE_CONFIG'.
How do we get this set? First make sure that you have an environment variable called PHP_IDE_CONFIG in your container. If you don't then get that set. I personally use a file to define my env variables. See https://docs.docker.com/compose/environment-variables/#set-environment-variables-in-containers and search for 'env_file'.
Once you get your env variables into your container, and it's still not working, then try this: Go to View > Tool Windows > Docker. Then click Edit Configurations (it's an icon). In there, make sure you are connected to Docker and you have a mapping of your vm path to your local path.
In addition to this, I used Oleg's answer to set
xdebug.extended_info=1
Although this in and of itself did not fix the issue for me, I am using this setting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With