Skip to content
This repository was archived by the owner on Nov 10, 2025. It is now read-only.

Commit b98e77a

Browse files
committed
minimal xdebug config and more
- forward open devcontainer port 80 by default - add local-dev xdebug vonfig \REPO\.vscode\launch.json
1 parent 6e47eed commit b98e77a

File tree

6 files changed

+132
-43
lines changed

6 files changed

+132
-43
lines changed

.devcontainer/.docker/php/xdebug.ini

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,36 @@ error_log = /var/log/php-errors.log
66
catch_workers_output = yes
77

88
[xdebug]
9+
# 'debug' means we're enabling step-by-step debugging
10+
xdebug.mode=debug
911

10-
; enables step by step debugging
11-
; xdebug.mode=debug,develop
12-
xdebug.mode=develop
12+
xdebug.client_port=9003
1313

14-
; xdebug.client_host=host.docker.internal
14+
# xdebug.client_host is the IP address of the system where VS Code runs
15+
# that IP address is DIFFERENT depending on WHERE VS Code is launched in (Windows/Mac, WSL(2), Container/devcontainer/codespaces)
16+
#
17+
# the PHP container sends debugging data OUT to xdebug.client_host:xdebug.client_port
1518

16-
; set this to 'yes' to ALWAYS start a request/
17-
; it will complain if not debugger is found listening
18-
; default value is xdebug.start_with_request=trigger, which should be fine
19-
;
20-
; xdebug.start_with_request=yes
21-
xdebug.discover_client_host=1
2219

23-
xdebug.client_port=9003
20+
# localhost is used when running btoh VS Code and PHP from within **the same PHP container**
21+
# after opening the project in the Container
22+
xdebug.client_host=localhost
23+
24+
# if using Docker Desktop 'host.docker.internal' is supposed to hold the IP Address of
25+
# the Docker host, but that's not always true. DOUBLE-CHECK
26+
27+
;xdebug.client_host=host.docker.internal
28+
29+
# 'yes': This will always initiate a debugging, profiling, or tracing session as soon as a request is received, without needing any specific trigger
30+
# 'no' : This will never initiate a session regardless of the presence of any trigger
31+
# 'trigger' : This will initiate a session only if a specific trigger (like a GET/POST variable or a cookie) is present in the request.
32+
xdebug.start_with_request=yes
33+
34+
# OPTIONAL: idekey
35+
# in the browser add a URL param (if not using a browser utility)
36+
# url.to.debug?XDEBUG_SESSION_START=PHPSTORM
37+
# sets up a coockie called "XDEBUG_SESSION_START" with the value "PHPSTORM", which is the "trigger"
38+
# xdebug.idekey=PHPSTORM
2439

25-
; No need. By default, this is redirected to the general log of
26-
; of your PHP container and visible from tools like Docker Desktop
27-
;
28-
;xdebug.log=/var/tmp/xdebug.log
29-
30-
; Color var_dumps when in CLI
31-
xdebug.cli_color=1
32-
33-
; redirect the xdebug log to the container's STDOUT (/proc/self/fd/1) or STDERR (/proc/self/fd/2)
34-
xdebug.log=/tmp/xdebug.log
35-
36-
; 2.x way to activate the debugger.
37-
; generates this message, if not debugger is listening:
38-
; NOTICE: PHP message: Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003
39-
;
40-
; xdebug.idekey=PHPSTORM
41-
42-
; NOTES
43-
;
44-
; the log error "Trigger value for 'XDEBUG_TRIGGER' not found, falling back to 'XDEBUG_SESSION'"
45-
; can be avoided by adding /?XDEBUG_SESSION=start to the page URL being browsed
46-
;
47-
; NOTICE: PHP message: Xdebug: [Step Debug] Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003
40+
# defines a log file. This is created (touch) and initialized (permissions) in the PHP container Dockerfile
41+
xdebug.log=/tmp/xdebug.log

.devcontainer/devcontainer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
// "xdebug.php-debug" = official XDEBUG extension
3232
"customizations": {
3333
"vscode": {
34-
"extensions": ["xdebug.php-debug"]
34+
"extensions": [
35+
"xdebug.php-debug"
36+
]
3537
}
36-
}
38+
},
39+
40+
"forwardPorts": [80]
3741
}

.devcontainer/docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ services:
4040
# disk local-path
4141
volumes:
4242
- ${PHP_WEBROOT_HOST_PATH}:${PHP_WEBROOT_CONTAINER_PATH}
43+
# we don't need to expose the port 9003 here for Xdebug because the
44+
# connection comes from inside the PHP container to the IDE via port 9003
4345

4446

4547
# MySQL Service

.vscode/launch.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Listen for Xdebug",
9+
"type": "php",
10+
"request": "launch",
11+
"port": 9003,
12+
// ${workspaceFolder} == directory where /.vscode/ is
13+
// the syntax is SERVER_PATH : LOCAL_PATH
14+
"pathMappings": {
15+
"/var/www/htdoc": "${workspaceFolder}/src"
16+
}
17+
},
18+
{
19+
"name": "Launch currently open script",
20+
"type": "php",
21+
"request": "launch",
22+
"program": "${file}",
23+
"cwd": "${fileDirname}",
24+
"port": 0,
25+
"runtimeArgs": [
26+
"-dxdebug.start_with_request=yes"
27+
],
28+
"env": {
29+
"XDEBUG_MODE": "debug,develop",
30+
"XDEBUG_CONFIG": "client_port=${port}"
31+
}
32+
},
33+
{
34+
"name": "Launch Built-in web server",
35+
"type": "php",
36+
"request": "launch",
37+
"runtimeArgs": [
38+
"-dxdebug.mode=debug",
39+
"-dxdebug.start_with_request=yes",
40+
"-S",
41+
"localhost:0"
42+
],
43+
"program": "",
44+
"cwd": "${workspaceRoot}",
45+
"port": 9003,
46+
"serverReadyAction": {
47+
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
48+
"uriFormat": "http://localhost:%s",
49+
"action": "openExternally"
50+
}
51+
}
52+
]
53+
}

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,20 @@ You'll need the following installed on your computer to follow along with this t
1313

1414
The article mentions several ways to get a Laravel development environment up and running.
1515

16+
# Preparing the Laravel project to run
17+
18+
## Dependencies
19+
20+
In the Laravel project folder, install the Composer dependencies with the command
21+
22+
`composer install`
23+
1624
## .env file
1725

26+
Laravel uses the .env file for environment-specific configurations, like database credentials, application key, and other settings. Create one from the included example file:
27+
28+
`cp .env.example .env`
29+
1830
#### Application key
1931

2032
Laravel might ask to generate a new application key. You can do it by running this command in the laravel project folder.
@@ -31,7 +43,37 @@ The complete URI looks like this:
3143

3244
`DB_URI=mongodb+srv://USERNAME:PASSWORD@clustername.subdomain.mongodb.net/?retryWrites=true&w=majority`
3345

34-
# Troubleshooting
46+
# Xdebug
47+
48+
The xdebug.php-debug VS Code extension is automatically installed if you launch via devcontainer.json.
49+
50+
If you are using our container directly (docker compose up), or via VS Code (devcontainer), we suggest the following Xdebug configs visual studio
51+
52+
### localhost
53+
54+
The debug config file is located in `<repository_dir>/.vscode/launch.json`
55+
56+
```json
57+
{
58+
"name": "Listen for Xdebug",
59+
"type": "php",
60+
"request": "launch",
61+
"port": 9003,
62+
"pathMappings": {
63+
// ${workspaceFolder} == directory where /.vscode/ is
64+
// the syntax is SERVER_PATH : LOCAL_PATH
65+
"/var/www/htdoc": "${workspaceFolder}/src"
66+
}
67+
},
68+
```
69+
70+
### devcontainer
71+
72+
- TODO
73+
74+
### Codespaces
75+
76+
- TODO
3577

3678

3779
# Disclaimer

src/public/index.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
22

3-
//echo "hello Laravel world";
4-
5-
//phpinfo();
6-
73
use Illuminate\Contracts\Http\Kernel;
84
use Illuminate\Http\Request;
95

@@ -54,8 +50,6 @@
5450

5551
$kernel = $app->make(Kernel::class);
5652

57-
// CRASH at the line below:
58-
5953
$response = $kernel->handle(
6054
$request = Request::capture()
6155
)->send();

0 commit comments

Comments
 (0)