From e4f9c67f9de813484d00eaa8adf73cfcfc59e965 Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 19 Jul 2021 18:13:28 +0100 Subject: [PATCH 1/3] Support for Linux on WSL Linux on WSL can still use the `host.docker.internal` host name to resolve the Docker VM, so we need to account for that too when switching between the Docker Engine IP used in Linux vs Linux on WSL. --- inc/composer/class-command.php | 10 ++++++++++ inc/composer/class-docker-compose-generator.php | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index 715b5e25..87e11ece 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 ! empty( $_ENV['WSL_INTEROP'] ); + } + } 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. From 8fc68c0fba7f914d3e6d1c575331f55a0ac6958d Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 19 Jul 2021 18:24:05 +0100 Subject: [PATCH 2/3] Update docs --- docs/using-xdebug.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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). From 0f949efc2453954f7a87817ad8b492f003d3d53e Mon Sep 17 00:00:00 2001 From: Robert O'Rourke Date: Mon, 19 Jul 2021 18:36:48 +0100 Subject: [PATCH 3/3] Use getenv instead as `$_ENV` isn't reliable Co-authored-by: Ryan McCue --- inc/composer/class-command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/composer/class-command.php b/inc/composer/class-command.php index 87e11ece..3b814604 100644 --- a/inc/composer/class-command.php +++ b/inc/composer/class-command.php @@ -681,7 +681,7 @@ protected function is_linux() : bool { * @return boolean */ public static function is_wsl() : bool { - return ! empty( $_ENV['WSL_INTEROP'] ); + return getenv( 'WSL_INTEROP' ) !== false; } }