Setting up an existing Drupal project with Lando + xdebug + phpStorm

Pasan Gamage
4 min readMay 25, 2021

--

I’ve tried a few times to understand how and what is necessary to spin up a Lando environment for an existing Drupal project but never managed to get it to work properly. Until recently I did.

And it is very simple and straight forward once you understand the basics— like most of the things in development.

There are only a few key things to follow.

Considering you already have Lando installed and working;

  1. Navigate to your existing project repository in your local machine.

2. Check your Drupal core path, whether it sits in web/ directory or root as this is necessary for the next step.

3. On your terminal app from the repository path root run lando init

This will prompt the below sequence;

4. Once that's done you will notice lando has created a new file named `.lando.yml`

You can update that file to your liking, but to enable Xdebug all it needs is

name: myapp
recipe: drupal8
config:
webroot: web
xdebug: true # enable xdebug
services:
appserver: # appserver is a default lando service name
overrides:
environment:
# support debugging Drush with XDEBUG.
PHP_IDE_CONFIG: "serverName=appserver"

5. From the terminal lando rebuild lando start

6. Once the rebuild is done run lando info to view the created environments configurations. These will be helpful for next steps and connecting your database to Drupal via default settings file.

Hint: Use values under external connection.

7. To configure phpStrom;

From the phpStorm app goto Preference > PHP

  • Remove all lines from include path table, if any.
  • Set PHP language level to desired — latest will be 7.4
  • To set the CLI interpreter we need to know the docker container in use.
  • You can find the current Lando environments docker container information by docker ps
  • And back in phpStorm click on the three dots on the far right side of CLI interpreter.
  • Click the + icon and choose “From Docker, Vagrant, VM, …”
  • Once the correct container is selected, in my case it was `devwithlando/php:7.4-apache-2` we can hit save and you should see something like this
  • And check if the Xdebug settings are as follows. These are mostly default settings.
  • You may need to enable `Break at first like in PHP scripts` option to make sure the debugger kicks in. Click Apply and OK
  • As displayed in the Pre-Configuration step on above screen grab, I’ll be using the Chrome browser toolbar Xdebug helper
  • Make sure this Chrome extensions settings are correct. Right click > Options > IDE Key dropdown should be set to phpstorm and PHPSTORM
  • Simply visit the local website. Make sure it loads.
  • Enable the Xdebug Helper extension.
  • Then from the phpStorm main interface click on Start listening for PHP debug connections.
  • Go back to Chrome and reload your website, you should get a pop-up from phpStrom
  • If you get this far it means you are all set.

Congratulations, you have setup Xdebug on your project.

--

--

Pasan Gamage
Pasan Gamage

Written by Pasan Gamage

Backend Developer | Motorbike enthusiast

No responses yet