# Debug PHP with XDebug and VSCode (docker edition)

If you are using Docker you will want to add this to your Dockerfile (runs when container being created).

```
RUN pecl install -f xdebug-2.9.8 \
&& rm -rf /tmp/pear \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini;

```

### Xdebug configuration

You can tweak the Xdebug configuration on file `docker-compose.yml`:

The laravel container definition has an environment variable for this purpose

```
- XDEBUG_CONFIG=remote_host=mysite.docker.laravel remote_port=9000 remote_enable=1 remote_autostart=1 default_enable=1 idekey=VSCODE remote_connect_back=1
```

Adjust it, in particular the `idekey` should match the key set in your IDE.

### VSCode setup

On VS Code we can use the [PHP Debug plugin](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug), once installed we can go to the Debug panel (Ctrl+Shift+D).

- Select **Add configuration** in the the dropdown at the top-right of the panel.

- In VSCode open the menu Run/Add Configuration, it opens launch.json. launch.json