Laravel Docker Xdebug



The following instructions should get you up and running with the XDebug in Visual Studio Code when using the Laradock PHP development environment for Docker.

Step 1. Enable Xdebug in the Laradock .env file

Edit the .env file in your laradock folder and set both of these settings to true.

Running specific PHP versions for Laravel can be quite useful, especially when working with legacy applications. I work on a range of different solutions with different versions of PHP and Laravel versions. To save me time reconfiguring my local environment’s PHP version and to better represent the live systems, I have opted for Docker based. Contribute to maimake/docker-laravel-xdebug development by creating an account on GitHub. Step Two: Configuring Xdebug. Before Docker, Xdebug was relatively straightforward to configure on a platform, in that it was a new set of the php.ini parameters – you’d either just edit the existing php.ini, or load in a custom ini or override. I had a lot of trouble trying to install XDebug in the Laravel Sail docker container. Once I did, I had trouble customizing the service name (from laravel.test). I also noticed th.

Laravel Docker Xdebug

Step 2. Retrieve the host IP

We’ll need to tell Xdebug the IP address of the remote host. From your laradock folder, type:

The response should look something like this:

From this, I can see my local IP address is: 129.168.1.129.

Step 3. Configure xdebug

Modify the php-fpm/xdebug.ini file in your Laradock folder with the following contents. Replace the IP address for the xdebug.remote_host setting with the IP address from step 2.

Modify the workspace/xdebug.ini file in your Laradock folder with exact same contents:

Step 4. Rebuild the PHP-FPM Container

Step 5. Restart your Laradock environment

Step 6. Install the PHP Debug Extension in Visual Studio Code

Xdebug Php Docker

Docker

Add the php-debug extension by Felix Becker to your project.

Docker Php Fpm Xdebug

Step 7. Add debug configuration to Visual Studio Code

In your VS Code project, add a .vscode/launch.json with these contents:

In the pathMappings section, replace “/Users/shawnhooper/work/project1” with the path where VS Code will find your project.

In order to use Xdebug, the first thing we’ll have to do is start the service in the PHP-FPM container.

From the laradock folder, run:

You should see a result like this come back, showing that Xdebug is enable:

Laravel docker phpstorm xdebugXdebug php docker

In VSCode, set a breakpoint on where you’d like the debugging to start running. You can do this either by clicking to the left of the line number in the editor, or by pressing F9 to toggle the breakpoint on and/off.

Docker

To enable the listener in VS Code, click on the green “run” icon in the sidebar to display the debugger.

and then click on the Run button in the debugger’s sidebar.

Or just press F5 to start the debugger. You should see the listener enabled in the VS Code footer. The footer will turn orange, and show “XDebug listening to Laradock”

Now, if I navigate in my browser to the file containing the breakpoint, the debugger will stop when it hits it.