Skip to content

Commit

Permalink
Merge pull request #307 from humanmade/backport-304-to-v6-branch
Browse files Browse the repository at this point in the history
[Backport v6-branch] Support for Linux on WSL
  • Loading branch information
roborourke authored Jul 19, 2021
2 parents 7d177da + 0f949ef commit 2abef92
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
15 changes: 9 additions & 6 deletions docs/using-xdebug.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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}"
}
Expand All @@ -104,14 +106,15 @@ 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}"
}
}
]
}
```
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).

Expand Down
10 changes: 10 additions & 0 deletions inc/composer/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
5 changes: 4 additions & 1 deletion inc/composer/class-docker-compose-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2abef92

Please sign in to comment.