Getting XDebug working with Lando using PHPStorm can be a bit of a journey as you piece together multiple blog posts and documentation from prior versions of Lando and PHPStorm. Here’s a step-by-step solution that works for me every time.
- In the local lando config file (
.lando.local.yml), add the following under config:
webroot: [web]rnxdebug: true
- Do a lando rebuild for the changes to take effect.
- Add a
/srv/includes/prepend.phpfile at the root of the repo (outside the web root).
prepend.phpwill be just an empty file.
- Add a server.
- In PHPStorm, go to Preferences > Languages & Frameworks > PHP > Servers.
- Click the + button.
- Give the server a name.
- Set Host to localhost and Port to 80/443 if using the .lndo.site url or the port number if using the localhost url. (Do
lando infoto get ports.)
- Set Debugger to Xdebug.
- Check the box for “Use path mappings.”
- Expand the files on the left to view the
/srv/includes/prepend.phpfile you added and under “Absolute path on the server” column for the
- Map the root by setting the root folder to
/app. The value of
/appcan be found by doing
lando sshfollowed by
- In Preferences > Languages & Frameworks > PHP > Debug, make sure the Xdebug: Debug port is listening on 9000 (for xdebug2) and 9003 for (xdebug3). So the textbox should be “9000,9003”.
- Turn on debugging in PHPStorm.
- Set a breakpoint.
- Accept the connection request.
- Walk through your code.
Stepping through your code with a debugger is a must-have when troubleshooting difficult issues. These steps should get you up and running without a ton of trial-and-error.
Making the web a better place to teach, learn, and advocate starts here...
When you subscribe to our newsletter!