» When the PHP project is built and run by Docker, edit the Dockerfile located at `docker/php/Dockerfile` and add the script below.
# install xdebug
RUN pecl install xdebug-3.1.5 \
&& docker-php-ext-enable xdebug
COPY ./xdebug.ini "${PHP_INI_DIR}/conf.d"
» Create `xdebug.ini` file in the same folder as the Dockerfile.
xdebug.mode=develop,debug
xdebug.client_host=host.docker.internal
xdebug.discover_client_host=1
xdebug.idekey=VSCODE
» Install VCS (Visual Studio Code) to support debugging the PHP project.
» Go to Extensions, search for `PHP Debug`, and click Install to add the PHP Debug extension.
» Press Run and Debug on the sidebar of Visual Studio Code or use the shortcut Ctrl + Shift + D to create `launch.json` file to save the configuration before starting debug session.
For local machine without using Docker
{
"version": "0.2.0",
"configurations": [
{
"name": "Local PHP Debug with Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"pathMappings": {
"C:\\Users\\your-username\\Documents\\flagtick": "${workspaceFolder}"
}
}
]
}
For Docker
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"pathMappings": {
"/var/www/flagtick": "${workspaceFolder}",
}
}
]
}
» Choose Run » Start Debugging (F5 shortcut) to initiate debugging session using the configuration in the `launch.json` file.
» Install Xdebug Helper in Chrome, right-click on the Xdebug icon and select `Options`. The Xdebug Helper settings will open. Choose `PhpStorm` as the IDE key, then click the Save button.
Then finally, start your application from the PHP project and make sure to enable the debug button in the Xdebug helper extension.