Skip to content

Commit

Permalink
Add 'make xdebug' command.
Browse files Browse the repository at this point in the history
  • Loading branch information
alxp committed Jun 2, 2024
1 parent b2e773f commit e5ec572
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 2 deletions.
51 changes: 51 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/drupal": "${workspaceRoot}/codebase",
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://islandora.traefik.me:([0-9]+)\\) started",
"uriFormat": "http://islandora.traefik.me:%s",
"action": "openExternally"
}
}
]
}
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ TARGET_MAX_CHAR_NUM=20
IS_DRUPAL_PSSWD_FILE_READABLE := $(shell test -r secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD -a -w secrets/live/DRUPAL_DEFAULT_ACCOUNT_PASSWORD && echo 1 || echo 0)
CMD := $(shell [ $(IS_DRUPAL_PSSWD_FILE_READABLE) -eq 1 ] && echo 'tee' || echo 'sudo -k tee')

PHP_VERSION=83
LATEST_VERSION := $(shell curl -s https://api.github.com/repos/desandro/masonry/releases/latest | grep '\"tag_name\":' | sed -E 's/.*\"([^\"]+)\".*/\1/')

PHP_FPM_PID=/var/run/php-fpm7/php-fpm7.pid
Expand Down Expand Up @@ -690,3 +691,36 @@ wait-for-drupal-locally:
echo "Waiting for https://$(DOMAIN) to be available..."; \
sleep 1; \
done


.PHONY: xdebug
## Turn on xdebug.
xdebug: TIMEOUT_VALUE=3600
xdebug:

$(MAKE) set-timeout TIMEOUT_VALUE=3600
sleep 10
docker compose exec -T drupal with-contenv bash -lc "apk add php${PHP_VERSION}-pecl-xdebug"
docker cp scripts/extra/xdebug.ini $$(docker compose ps -q drupal):/etc/php${PHP_VERSION}/conf.d/xdebug.ini
-docker compose exec -T drupal with-contenv bash -lc "chown root:root /etc/php${PHP_VERSION}_/conf.d/xdebug.ini"
docker compose restart drupal
sleep 6
docker compose exec -T drupal with-contenv bash -lc "php -i | grep xdebug"

.phony: set-timeout
## Update all PHP and NGinx timeouts to TIMEOUT_VALUE
set-timeout:
$(SED_DASH_I) 's/NGINX_FASTCGI_READ_TIMEOUT: .*s/NGINX_FASTCGI_READ_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_FASTCGI_CONNECT_TIMEOUT: .*s/NGINX_FASTCGI_CONNECT_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_FASTCGI_SEND_TIMEOUT: .*s/NGINX_FASTCGI_SEND_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_KEEPALIVE_TIMEOUT: .*s/NGINX_KEEPALIVE_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_PROXY_CONNECT_TIMEOUT: .*s/NGINX_PROXY_CONNECT_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_PROXY_READ_TIMEOUT: .*s/NGINX_PROXY_READ_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_PROXY_SEND_TIMEOUT: .*s/NGINX_PROXY_SEND_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/NGINX_SEND_TIMEOUT: .*s/NGINX_SEND_TIMEOUT: $(TIMEOUT_VALUE)s/g' docker-compose.yml
$(SED_DASH_I) 's/PHP_DEFAULT_SOCKET_TIMEOUT: ".*"/PHP_DEFAULT_SOCKET_TIMEOUT: "$(TIMEOUT_VALUE)"/g' docker-compose.yml
$(SED_DASH_I) 's/PHP_MAX_EXECUTION_TIME: ".*"/PHP_MAX_EXECUTION_TIME: "$(TIMEOUT_VALUE)"/g' docker-compose.yml
$(SED_DASH_I) 's/PHP_MAX_INPUT_TIME: ".*"/PHP_MAX_INPUT_TIME: "$(TIMEOUT_VALUE)"/g' docker-compose.yml
$(SED_DASH_I) 's/PHP_PROCESS_CONTROL_TIMEOUT: ".*"/PHP_PROCESS_CONTROL_TIMEOUT: "$(TIMEOUT_VALUE)"/g' docker-compose.yml
$(SED_DASH_I) 's/PHP_REQUEST_TERMINATE_TIMEOUT: ".*"/PHP_REQUEST_TERMINATE_TIMEOUT: "$(TIMEOUT_VALUE)"/g' docker-compose.yml
docker compose up -d --force-recreate --remove-orphans
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ To enable using secrets prior to running the `make` commands, copy sample.env
to .env. Set `USE_SECRETS=true` in your .env file. Make a copy of the files in
/secrets/template/ to /secrets/live/.

To enable using secrets after run `make local` or `make up`, set
To enable using secrets after run `make local` or `make up`, set
`USE_SECRETS=true` in your .env file. When you run `make docker-compose.yml`, a
large block of `secrets` will be added at the top of your `docker-compose.yml`
file.
Expand Down Expand Up @@ -259,6 +259,26 @@ Setting admin password now

```

### Enable XDebug

```shell
make xdebug
```

This will download and enable the [XDebug](https://xdebug.org)
PHP debugger.

It also changes all of the PHP and Nginx timeouts so your
debugging session doesn't get shut down while you're working.

Bringing ISLE down and back up will disable the debugger again.

You can put custom XDebug config settings in scripts/extra/xdebug.ini

See the documentation for your code editor for further
details on how to debug PHP applications.
Specifically the 'Listen for XDebug' command.

## Services

Islandora is composed of many different services, this project has split these
Expand Down Expand Up @@ -386,7 +406,7 @@ lowercasename:
echo "first line in command needs to be indented. There are exceptions to this, review functions in the Makefile for examples of these exceptions."
```

NOTE: A target you add in the custom.Makefile will not override an existing target with the same label in this repository's defautl Makefile.
NOTE: A target you add in the custom.Makefile will not override an existing target with the same label in this repository's defautl Makefile.

Running the new `custom.Makefile` commands are exactly the same as running any other Makefile command. Just run `make` and the function's name.
```bash
Expand Down
58 changes: 58 additions & 0 deletions scripts/extra/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/drupal": "${workspaceRoot}/codebase",
}
},
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"url": "https://islandora.traefik.me",
"webRoot": "${workspaceFolder}/codebase/web"
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://islandora.traefik.me:([0-9]+)\\) started",
"uriFormat": "http://islandora.traefik.me:%s",
"action": "openExternally"
}
}
]
}
9 changes: 9 additions & 0 deletions scripts/extra/xdebug.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=true
xdebug.cli_color=1
xdebug.discover_client_host=0
xdebug.client_host=host.docker.internal
xdebug.max_nesting_level=512
xdebug.log_level = 0
xdebug.log=/var/log/xdebug.log

0 comments on commit e5ec572

Please sign in to comment.