Skip to content

Commit 232676a

Browse files
josecarlospeer-cloudjorge07
authored andcommitted
feat: devcontainer.json, explicit sshd_config, Xdebug 3 docs
.devcontainer/devcontainer.json (new) Modern VS Code Dev Containers config. Uses jorge07/alpine-php:8.3-dev, forwards ports 22 and 9003, pre-installs php-debug + Intelephense, sets php.validate.executablePath and intelephense.phpVersion. devfs/etc/ssh/sshd_config (new, all 4 versions) Replaces the brittle 'sed -i s/#PermitRootLogin...' hack with an explicit, self-documenting sshd_config. Settings: - PermitRootLogin yes, PasswordAuthentication yes (IDE SSH compat) - PubkeyAuthentication yes (allows key-based auth as alternative) - TCPKeepAlive + ClientAlive (stable IDE sessions) - AllowTcpForwarding + GatewayPorts (remote debug port forwarding) Dockerfile sed line removed from all four PHP versions. doc/IDE.md (rewritten) Updated from PHP 7.x/Xdebug 2 era to current: - VS Code Dev Containers workflow with launch.json config - PHPStorm SSH remote interpreter setup (modern UI paths) - Xdebug 3 trigger mode: XDEBUG_SESSION env var, port 9003 - Side-by-side Xdebug 2 vs 3 config table - CLI debugging examples with docker exec Build-tested locally: 8.3 dev image, sshd_config confirmed present. Closes #104
1 parent a8b341c commit 232676a

10 files changed

Lines changed: 257 additions & 47 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "alpine-php dev",
3+
4+
// Use the latest stable dev image. Change to 8.1-dev, 8.2-dev, or 8.4-dev as needed.
5+
"image": "jorge07/alpine-php:8.3-dev",
6+
7+
// Mount the workspace at /app (matches the container's WORKDIR)
8+
"workspaceFolder": "/app",
9+
"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind,consistency=cached",
10+
11+
// Forward Xdebug port and SSH port
12+
"forwardPorts": [9003, 22],
13+
"portsAttributes": {
14+
"9003": { "label": "Xdebug", "onAutoForward": "silent" },
15+
"22": { "label": "SSH (IDE integration)", "onAutoForward": "silent" }
16+
},
17+
18+
// VS Code extensions for PHP development
19+
"customizations": {
20+
"vscode": {
21+
"extensions": [
22+
"xdebug.php-debug",
23+
"bmewburn.vscode-intelephense-client",
24+
"junstyle.php-cs-fixer",
25+
"neilbrayfield.php-docblocker"
26+
],
27+
"settings": {
28+
"php.validate.executablePath": "/usr/bin/php",
29+
"intelephense.environment.phpVersion": "8.3",
30+
"php.debug.ideKey": "VSCODE"
31+
}
32+
}
33+
},
34+
35+
// Remote user — root matches the dev image's default
36+
"remoteUser": "root",
37+
38+
// Override CMD to keep the container running with supervisor
39+
"overrideCommand": false
40+
}

8.1/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ RUN apk add -U --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/v3.
8383
make \
8484
zip \
8585
&& rm -rf /var/cache/apk/* \
86-
&& sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
8786
&& echo "${USER}:${PASSWORD}" | chpasswd \
8887
&& ssh-keygen -A \
8988
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION}

8.1/devfs/etc/ssh/sshd_config

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# OpenSSH configuration for alpine-php dev image
2+
# Intended for local development only — do not use in production.
3+
4+
Port 22
5+
AddressFamily inet
6+
Protocol 2
7+
8+
# Authentication
9+
PermitRootLogin yes
10+
PasswordAuthentication yes
11+
PubkeyAuthentication yes
12+
AuthorizedKeysFile .ssh/authorized_keys
13+
PermitEmptyPasswords no
14+
IgnoreRhosts yes
15+
HostbasedAuthentication no
16+
17+
# Keep connections alive (important for IDE SSH sessions)
18+
TCPKeepAlive yes
19+
ClientAliveInterval 60
20+
ClientAliveCountMax 3
21+
22+
# Forwarding (required for IDE remote debugging port forwarding)
23+
AllowTcpForwarding yes
24+
GatewayPorts yes
25+
26+
# SFTP
27+
Subsystem sftp /usr/lib/ssh/sftp-server

8.2/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ RUN apk add -U --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/v3.
8888
# Delete APK cache.
8989
&& rm -rf /var/cache/apk/* \
9090
# Create ssh user for dev.
91-
&& sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
9291
&& echo "${USER}:${PASSWORD}" | chpasswd \
9392
&& ssh-keygen -A \
9493
# Download composer.

8.2/devfs/etc/ssh/sshd_config

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# OpenSSH configuration for alpine-php dev image
2+
# Intended for local development only — do not use in production.
3+
4+
Port 22
5+
AddressFamily inet
6+
Protocol 2
7+
8+
# Authentication
9+
PermitRootLogin yes
10+
PasswordAuthentication yes
11+
PubkeyAuthentication yes
12+
AuthorizedKeysFile .ssh/authorized_keys
13+
PermitEmptyPasswords no
14+
IgnoreRhosts yes
15+
HostbasedAuthentication no
16+
17+
# Keep connections alive (important for IDE SSH sessions)
18+
TCPKeepAlive yes
19+
ClientAliveInterval 60
20+
ClientAliveCountMax 3
21+
22+
# Forwarding (required for IDE remote debugging port forwarding)
23+
AllowTcpForwarding yes
24+
GatewayPorts yes
25+
26+
# SFTP
27+
Subsystem sftp /usr/lib/ssh/sftp-server

8.3/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ RUN apk add -U --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/v3.
8383
make \
8484
zip \
8585
&& rm -rf /var/cache/apk/* \
86-
&& sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
8786
&& echo "${USER}:${PASSWORD}" | chpasswd \
8887
&& ssh-keygen -A \
8988
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION}

8.3/devfs/etc/ssh/sshd_config

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# OpenSSH configuration for alpine-php dev image
2+
# Intended for local development only — do not use in production.
3+
4+
Port 22
5+
AddressFamily inet
6+
Protocol 2
7+
8+
# Authentication
9+
PermitRootLogin yes
10+
PasswordAuthentication yes
11+
PubkeyAuthentication yes
12+
AuthorizedKeysFile .ssh/authorized_keys
13+
PermitEmptyPasswords no
14+
IgnoreRhosts yes
15+
HostbasedAuthentication no
16+
17+
# Keep connections alive (important for IDE SSH sessions)
18+
TCPKeepAlive yes
19+
ClientAliveInterval 60
20+
ClientAliveCountMax 3
21+
22+
# Forwarding (required for IDE remote debugging port forwarding)
23+
AllowTcpForwarding yes
24+
GatewayPorts yes
25+
26+
# SFTP
27+
Subsystem sftp /usr/lib/ssh/sftp-server

8.4/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ RUN apk add -U --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edg
8585
make \
8686
zip \
8787
&& rm -rf /var/cache/apk/* \
88-
&& sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
8988
&& echo "${USER}:${PASSWORD}" | chpasswd \
9089
&& ssh-keygen -A \
9190
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer --version=${COMPOSER_VERSION}

8.4/devfs/etc/ssh/sshd_config

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# OpenSSH configuration for alpine-php dev image
2+
# Intended for local development only — do not use in production.
3+
4+
Port 22
5+
AddressFamily inet
6+
Protocol 2
7+
8+
# Authentication
9+
PermitRootLogin yes
10+
PasswordAuthentication yes
11+
PubkeyAuthentication yes
12+
AuthorizedKeysFile .ssh/authorized_keys
13+
PermitEmptyPasswords no
14+
IgnoreRhosts yes
15+
HostbasedAuthentication no
16+
17+
# Keep connections alive (important for IDE SSH sessions)
18+
TCPKeepAlive yes
19+
ClientAliveInterval 60
20+
ClientAliveCountMax 3
21+
22+
# Forwarding (required for IDE remote debugging port forwarding)
23+
AllowTcpForwarding yes
24+
GatewayPorts yes
25+
26+
# SFTP
27+
Subsystem sftp /usr/lib/ssh/sftp-server

doc/IDE.md

Lines changed: 109 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,130 @@
1-
# IDE integration
1+
# IDE Integration
22

3-
### Up container
3+
## Start the dev container
44

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:
86

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+
```
1114

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)
1318

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-
![Remote](https://raw.githubusercontent.com/jorge07/alpine-php/master/doc/images/remote-interpreter.png)
19+
**Default credentials:** `root` / `root`
2820

29-
**Mapping**
30-
![Remote](https://raw.githubusercontent.com/jorge07/alpine-php/master/doc/images/mapping.png)
21+
---
3122

32-
Now your breakpoints should work.
23+
## VS Code (Dev Containers)
3324

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.
3526

36-
### Steps in detail
27+
### Xdebug launch config
3728

38-
**Credentials**
29+
Add to `.vscode/launch.json`:
3930

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+
```
4158

42-
**Default Credentials Values:**
59+
Set the `XDEBUG_SESSION` env var or use the browser extension to trigger a debug session. For CLI scripts:
4360

44-
- user: root
45-
- pass: root
61+
```sh
62+
docker exec php-dev sh -c "XDEBUG_SESSION=1 php /app/bin/console something"
63+
```
4664

47-
**Binary path**
65+
---
4866

49-
- /usr/bin/php
67+
## PHPStorm
5068

51-
**Xdebug.so path**
69+
### Remote interpreter via SSH
5270

53-
- /usr/lib/php{7}/modules/xdebug.so
71+
**Languages & Frameworks → PHP → Add → SSH Credentials**
5472

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` |
5680

57-
Add your **Path mapping** from your workspace folder to the `/app` folder inside the container.
81+
**Path mappings:** `<project root>``/app`
5882

59-
**Xdebug**
83+
### Xdebug 3 configuration
6084

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

Comments
 (0)