If you are developing the project using PhpStorm, you can configure your IDE in order to make use of the XDebug debugger. The steps to enable it are the following:
-
Check if your
.envfile had the valuetrueset for the variableENABLE_XDEBUG_SUPPORT. If not, update the value and rebuild the container with the commandmake. -
Open PHPStorm and head to the settings
-
Head to
Preferences | Languages & Frameworks | PHPand click on the button...in order to configure a new interpreter. -
Click on the
+button choosingFrom Docker, Vagrant, VM, etc. -
Choose
Docker Composefrom the radio button choices. -
Add a new server (if no one has already been configured) by clicking on
New...in Server row and by choosingDocker for Windows(if on Windows)Docker for Mac(if on MacOS)Unix socket(if on Linux). -
In the dropdown relative to "Service", choose
php. -
Click on
Okand wait for the IDE to check that everything is ok. -
Click on
Okonce again to head back to the main settings window. -
On the line
Docker container, click on the folder icon. -
Click on
Applyand head to the sectionPreferences | Languages & Frameworks | PHP | Debug -
Update the
Remote portvalue to9001(or the one you chose in the.envfile for theXD_REMOTE_PORTvariable) then click onApplyagain. -
Head to
Preferences | Languages & Frameworks | PHP | Serversand add a new server with the+icon. -
Name it as the
COMPOSE_PROJECT_NAMEvariable in the.envfile and as host, set the url of the project, then check theUse port mappingscheckbox. -
Under the "Project files" section, add as the
Absolute path on the server, paste/var/www/html/PROJECT-DIRrelated to the root directory of the project. -
Complete the procedure by clicking on
Applyand closing the settings window.
-
-
the configuration is now completed and you should be able to easily debug your php code with the aid of
xDebug.
If you are developing the project using VSCode, you can configure your Editor in order to make use of the xDebug debugger. The steps to enable it are the following:
-
Check if your
.envfile had the valuetrueset for the variableENABLE_XDEBUG_SUPPORT. If not, update the value and rebuild the container with the commandmake. -
Open VSCode and head to the
Extensionstab -
Search the extension called
PHP Debugand install it. -
Head to the
Debugsection and on the top-bar click on the cog and chosePHPfrom the selector in order to add a new PHP debug configuration -
A new
launch.jsonshould open with 2 preconfigured configuration objects. -
Edit the one named "Listen for XDebug" by updating the
portvalue according to your environment file configuration -
Add a new property called
pathMappingswhich type has to be Object. -
Inside the newly created object, create a new field. The key of the field has to be the path to the project module inside the docker container and its value must be the full path of the project module root folder inside your host computer. The result should be similar to the following snippet:
{ "version": "0.2.0", "configurations": [ { "name": "Listen for XDebug", "type": "php", "request": "launch", "port": "<ENV XD_REMOTE_PORT VALUE>", "pathMappings": { "/var/www/html/<MODULE FOLDER>": "/PATH/TO/PROJECT/<MODULE FOLDER>" } } ] } -
Once the config file has been saved, you should be able to easily debug your php code with the aid of
xDebug.