|
1 | | -# IDE integration |
| 1 | +# IDE Integration |
2 | 2 |
|
3 | | -### Up container |
| 3 | +## Start the dev container |
4 | 4 |
|
5 | | -Run this in your project root path: |
6 | | - |
7 | | - docker run -itd --name php7 -v $PWD:/app -p 2244:22 jorge07/alpine-php:7.4-dev |
| 5 | +Run this in your project root: |
8 | 6 |
|
9 | | -- `-v $PWD:/app` will create a volume to share the host folder with the container |
10 | | -- `-p 2244:22` will export the 22 container port to the 2244 host machine. This will allow us to connect the IDE via SSH. |
| 7 | +```sh |
| 8 | +docker run -itd --name php-dev \ |
| 9 | + -v $PWD:/app \ |
| 10 | + -p 2244:22 \ |
| 11 | + -p 9003:9003 \ |
| 12 | + jorge07/alpine-php:8.3-dev |
| 13 | +``` |
11 | 14 |
|
12 | | -### PHPSTORM |
| 15 | +- `-v $PWD:/app` — mounts your project at `/app` inside the container |
| 16 | +- `-p 2244:22` — SSH port for remote interpreter |
| 17 | +- `-p 9003:9003` — Xdebug 3 port (default, replaces 9000 from Xdebug 2) |
13 | 18 |
|
14 | | -- Languages & Frameworks > PHP > Add > Remote... |
15 | | - - SSH Credentials |
16 | | - - HOST |
17 | | - - Docker-machine: 192.168.99.100 ([Recommended](https://github.com/adlogix/docker-machine-nfs)) |
18 | | - - Linux or Docker4{MAc|Windows}: localhost |
19 | | - - port: 2244 (or the one you choose on the docker run command) |
20 | | - - user: root |
21 | | - - pass: root |
22 | | - - Executable: /usr/bin/php |
23 | | - - Path mappings: |
24 | | - - <Project root> -> /app |
25 | | - |
26 | | -**Remote Interpreter** |
27 | | - |
| 19 | +**Default credentials:** `root` / `root` |
28 | 20 |
|
29 | | -**Mapping** |
30 | | - |
| 21 | +--- |
31 | 22 |
|
32 | | -Now your breakpoints should work. |
| 23 | +## VS Code (Dev Containers) |
33 | 24 |
|
34 | | -You can also use the oficial PHPStrom documentation for [remote connexion via SSH Credentials](https://confluence.jetbrains.com/display/PhpStorm/Working+with+Remote+PHP+Interpreters+in+PhpStorm) they will explain it better than me. |
| 25 | +The repo ships a `.devcontainer/devcontainer.json`. Open the project in VS Code and click **Reopen in Container** — it will use `jorge07/alpine-php:8.3-dev` and pre-install the PHP Debug and Intelephense extensions. |
35 | 26 |
|
36 | | -### Steps in detail |
| 27 | +### Xdebug launch config |
37 | 28 |
|
38 | | -**Credentials** |
| 29 | +Add to `.vscode/launch.json`: |
39 | 30 |
|
40 | | -Use the ARG variables to change the *USER* and *PASSWORD* for ssh and *COMPOSER_VERSION* to select an specific version on the build. |
| 31 | +```json |
| 32 | +{ |
| 33 | + "version": "0.2.0", |
| 34 | + "configurations": [ |
| 35 | + { |
| 36 | + "name": "Listen for Xdebug", |
| 37 | + "type": "php", |
| 38 | + "request": "launch", |
| 39 | + "port": 9003, |
| 40 | + "pathMappings": { |
| 41 | + "/app": "${workspaceFolder}" |
| 42 | + } |
| 43 | + }, |
| 44 | + { |
| 45 | + "name": "Debug CLI script", |
| 46 | + "type": "php", |
| 47 | + "request": "launch", |
| 48 | + "port": 9003, |
| 49 | + "pathMappings": { |
| 50 | + "/app": "${workspaceFolder}" |
| 51 | + }, |
| 52 | + "runtimeExecutable": "php", |
| 53 | + "program": "${file}" |
| 54 | + } |
| 55 | + ] |
| 56 | +} |
| 57 | +``` |
41 | 58 |
|
42 | | -**Default Credentials Values:** |
| 59 | +Set the `XDEBUG_SESSION` env var or use the browser extension to trigger a debug session. For CLI scripts: |
43 | 60 |
|
44 | | -- user: root |
45 | | -- pass: root |
| 61 | +```sh |
| 62 | +docker exec php-dev sh -c "XDEBUG_SESSION=1 php /app/bin/console something" |
| 63 | +``` |
46 | 64 |
|
47 | | -**Binary path** |
| 65 | +--- |
48 | 66 |
|
49 | | -- /usr/bin/php |
| 67 | +## PHPStorm |
50 | 68 |
|
51 | | -**Xdebug.so path** |
| 69 | +### Remote interpreter via SSH |
52 | 70 |
|
53 | | -- /usr/lib/php{7}/modules/xdebug.so |
| 71 | +**Languages & Frameworks → PHP → Add → SSH Credentials** |
54 | 72 |
|
55 | | -**Server mappings** |
| 73 | +| Field | Value | |
| 74 | +|---|---| |
| 75 | +| Host | `localhost` (or your Docker host IP) | |
| 76 | +| Port | `2244` | |
| 77 | +| User | `root` | |
| 78 | +| Password | `root` | |
| 79 | +| PHP executable | `/usr/bin/php` | |
56 | 80 |
|
57 | | -Add your **Path mapping** from your workspace folder to the `/app` folder inside the container. |
| 81 | +**Path mappings:** `<project root>` → `/app` |
58 | 82 |
|
59 | | -**Xdebug** |
| 83 | +### Xdebug 3 configuration |
60 | 84 |
|
61 | | -If you want to [debug php script commands remotely](https://confluence.jetbrains.com/display/PhpStorm/Debugging+PHP+CLI+scripts+with+PhpStorm) (I.E: php bin/console something) with Your IDE (PHPStorm in this case): |
62 | | - |
63 | | - - Set the PHP_IDE_CONFIG environment variable with **serverName=SomeName** |
64 | | - - where **SomeName** is the name of the server configured in *Settings / Preferences | Languages & Frameworks | PHP | Servers* in the PHPStorm IDE. |
| 85 | +**Languages & Frameworks → PHP → Debug** |
| 86 | + |
| 87 | +| Setting | Value | |
| 88 | +|---|---| |
| 89 | +| Debug port | `9003` | |
| 90 | +| Can accept external connections | ✅ | |
| 91 | + |
| 92 | +**Run → Edit Configurations → PHP Remote Debug** |
| 93 | + |
| 94 | +| Setting | Value | |
| 95 | +|---|---| |
| 96 | +| Server | (the SSH server you configured above) | |
| 97 | +| IDE key | `PHPSTORM` | |
| 98 | + |
| 99 | +For CLI debugging, set the env var before running: |
| 100 | + |
| 101 | +```sh |
| 102 | +docker exec php-dev sh -c "PHP_IDE_CONFIG='serverName=MyServer' XDEBUG_SESSION=PHPSTORM php /app/script.php" |
| 103 | +``` |
| 104 | + |
| 105 | +### Key differences from Xdebug 2 |
| 106 | + |
| 107 | +| | Xdebug 2 | Xdebug 3 | |
| 108 | +|---|---|---| |
| 109 | +| Default port | `9000` | `9003` | |
| 110 | +| Trigger env var | `XDEBUG_REMOTE_ENABLE=1` | `XDEBUG_SESSION=1` | |
| 111 | +| ini key (enable) | `xdebug.remote_enable=1` | `xdebug.mode=debug` | |
| 112 | +| ini key (host) | `xdebug.remote_host` | `xdebug.client_host` | |
| 113 | +| ini key (port) | `xdebug.remote_port` | `xdebug.client_port` | |
| 114 | + |
| 115 | +The images ship with `xdebug.mode=debug` and `xdebug.start_with_request=trigger` — Xdebug only activates when a session is triggered, not on every request. |
| 116 | + |
| 117 | +--- |
| 118 | + |
| 119 | +## SSH credentials (custom) |
| 120 | + |
| 121 | +Pass build args to change the default user/password: |
| 122 | + |
| 123 | +```sh |
| 124 | +docker build \ |
| 125 | + --build-arg USER=myuser \ |
| 126 | + --build-arg PASSWORD=mypassword \ |
| 127 | + -t myapp:dev \ |
| 128 | + --target dev \ |
| 129 | + -f 8.3/Dockerfile 8.3/ |
| 130 | +``` |
0 commit comments