Search code examples
phpvagrantsymfony4xdebughomestead

Xdebug unable to read Dotenv.php


The environment:

  • PHP - v7.4
  • Symfony - v4.1
  • Vagrant - v2.2.7
  • Homestead - v9.5.1
  • VSCode

My launch.json file configuration:

     {
         "name": "Listen for myapp",
         "type": "php",
         "request": "launch",
         "port": 9000,
         "pathMappings": {
              "/home/vagrant/code": "/home/user/code",
              "/home/vagrant/code/myapp": "/home/user/code/myapp",
              "/home/vagrant/code/myapp/public": "/home/user/code/myapp/public"
            },
      },

My Homestead.yaml file:

     - map: myapp.test
          to: /home/vagrant/code/myapp/public
          type: symfony4

My xdebug.ini config (located in /etc/php/7.4/cli/conf.d/20-xdebug.ini):

    zend_extension=xdebug.so
    xdebug.remote_enable=1
    xdebug.remote_autostart=1
    xdebug.idekey = VSCODE

When I am running xdebugger (VSCode PHP debug extension), it is showing

>Unable to open 'Dotenv.php': Unable to read file '/home/vagrant/code/myapp/vendor/symfony/dotenv/Dotenv.php' (Error: Unable to resolve non-existing file '/home/vagrant/code/myapp/vendor/symfony/dotenv/Dotenv.php').

Can anyone give any guidance on it?

Update 1:

It seems it is unable to read this line itself:

    (new Dotenv())->load(__DIR__.'/../.env');

.env file has permission 644, I tried changing it to 775 and tried again but still got same issue.

Both location of .env and Dotenv.php is correct, currently .env has permission 644 and Dotenv.php has 775.


Solution

  • I was having 4 applications, all of them having launch.json with respective pathmappings and I added all of them to a workspace, so the default configurations that got generated were same in all launch.json and it was creating confusion for xdebug config. Removed all launch.json and created one for the whole workspace and the problem got resolved.