Laravel Docker Xdebug



  1. Laravel Docker Phpstorm Xdebug
  2. Phpstorm Xdebug Docker Cli
  3. Phpstorm Xdebug Docker
  4. Xdebug Php Docker
  5. Docker Php Fpm Xdebug

Creating a Simple Laravel Docker Environment Since I started at liquidfish a little over a year ago I was introduced to the wonderful world of Laravel Homestead. Laravel Homestead is great, it supports multiple php versions, xDebug, MySQL and allows the user to install any other required software straight into the virtual machine.

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

Laravel

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

Laravel Docker Phpstorm Xdebug

  1. Next to 'PHP Interpreter' to bring up the interpreters. Choose 'Docker (SSH)' in the left pane and click on the little folder icon on the bottom of the window next to 'Configuration options'. In the pop up enter xdebug.remotehost as key and host.docker.internal as value and hit 'OK'.
  2. 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.
  3. If you are using Docker, Use these settings in your php.ini file: //php.ini XDebug xdebug.remoteenable = 1 xdebug.remoteautostart = 1 xdebug.remotehost = host.docker.internal xdebug.remoteport = 9001 As of Docker version 18.03, host.docker.internal points to host IP address on Mac / Windows. For Linux, you can use this workaround.

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

Phpstorm Xdebug Docker Cli

Laravel Docker Xdebug

Step 5. Restart your Laradock environment

Docker

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

Phpstorm xdebug docker cli

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

Laravel

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.

Phpstorm Xdebug Docker

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:

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.

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.

Xdebug Php Docker

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”

Docker Php Fpm Xdebug

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