diff --git a/docs/using-xdebug.md b/docs/using-xdebug.md index e2e1db7a..5cca5af3 100644 --- a/docs/using-xdebug.md +++ b/docs/using-xdebug.md @@ -58,10 +58,11 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi ### VSCode +1. Install a [PHP Debug extension](https://github.com/xdebug/vscode-php-debug) 1. Open the debug tab (the bug icon on the menu sidebar). -2. In the dropdown menu at the top of the left hand side bar choose "Add configuration". -3. In the popup that appears select "PHP" as your environment. -4. You will be taken a new file called `.vscode/launch.json` with the default settings: +1. In the dropdown menu at the top of the left hand side bar choose "Add configuration". +1. In the popup that appears select "PHP" as your environment. +1. You will be taken a new file called `.vscode/launch.json` with the default settings: ```json { "version": "0.2.0", @@ -78,12 +79,12 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi "request": "launch", "program": "${file}", "cwd": "${fileDirname}", - "port": 9003, + "port": 9003 } ] } ``` -5. Add the following `pathMappings` property to each configuration: +1. Add the following `hostname` and `pathMappings` property to each configuration: ```json { "version": "0.2.0", @@ -93,6 +94,7 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi "type": "php", "request": "launch", "port": 9003, + "hostname": "0.0.0.0", "pathMappings": { "/usr/src/app": "${workspaceRoot}" } @@ -104,6 +106,7 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi "program": "${file}", "cwd": "${fileDirname}", "port": 9003, + "hostname": "0.0.0.0", "pathMappings": { "/usr/src/app": "${workspaceRoot}" } @@ -111,7 +114,7 @@ Xdebug is configured to connect to the default port 9003 so there should be a mi ] } ``` -6. You are done, click the green play button to start the debug client. +1. You are done, click the green play button to start the debug client. For more information on the available configuration options, including Xdebug settings, [view the VSCode Debugging documentation here](https://go.microsoft.com/fwlink/?linkid=830387). diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index 715b5e25..3b814604 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -674,4 +674,14 @@ protected function get_project_subdomain() : string { protected function is_linux() : bool { return in_array( php_uname( 's' ), [ 'BSD', 'Linux', 'Solaris', 'Unknown' ], true ); } + + /** + * Check if the current host is WSL. + * + * @return boolean + */ + public static function is_wsl() : bool { + return getenv( 'WSL_INTEROP' ) !== false; + } + } diff --git a/inc/composer/class-docker-compose-generator.php b/inc/composer/class-docker-compose-generator.php index d149f7cc..69cd3553 100644 --- a/inc/composer/class-docker-compose-generator.php +++ b/inc/composer/class-docker-compose-generator.php @@ -140,7 +140,10 @@ protected function get_php_reusable() : array { 'ALTIS_ANALYTICS_PINPOINT_ENDPOINT' => "https://pinpoint-{$this->hostname}", 'ALTIS_ANALYTICS_COGNITO_ENDPOINT' => "https://cognito-{$this->hostname}", // Enables XDebug for all processes and allows setting remote_host externally for Linux support. - 'XDEBUG_CONFIG' => sprintf( 'client_host=%s', $this->is_linux() ? '172.17.0.1' : 'host.docker.internal' ), + 'XDEBUG_CONFIG' => sprintf( + 'client_host=%s', + $this->is_linux() && ! Command::is_wsl() ? '172.17.0.1' : 'host.docker.internal' + ), 'PHP_IDE_CONFIG' => "serverName={$this->hostname}", 'XDEBUG_SESSION' => $this->hostname, // Set XDebug mode, fall back to "off" to avoid any performance hits.