Not able to debug laravel applications using XR in Docker environment
gopibabus opened this issue · 1 comments
gopibabus commented
Here are my config
docker-compose.yml
services:
hoa-webserver:
image: hoa-webserver
container_name: hoa-webserver
build:
context: .
dockerfile: docker/Dockerfile
depends_on:
- hoa-sql-server
- hoa-xr-server
links:
- hoa-sql-server
- hoa-xr-server
volumes:
- .:/var/www/html
networks:
- hoa-network
ports:
- "${APP_HOST_PORT}:80"
hoa-sql-server:
image: postgres:latest
container_name: hoa-sql-server
volumes:
- ./sql_data:/var/lib/postgresql/data
networks:
- hoa-network
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
ports:
- "${DB_HOST_PORT}:${DB_PORT}"
hoa-xr-server:
image: hoa-xr-server
container_name: hoa-xr-server
build:
context: .
dockerfile: docker/XRDockerfile
networks:
- hoa-network
environment:
- BROWSER=/dev/null
ports:
- "27420:27420"
networks:
hoa-network:
driver: bridge
volumes:
sql_data:
xr.php
<?php
return [
'isEnabled' => true,
'isHttps' => false,
'host' => 'hoa-xr-server',
'port' => 27420,
'key' => getenv('APP_KEY'),
];
index.php
<?php
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
require __DIR__.'/../vendor/autoload.php';
require __DIR__.'/../xr.php';
// Bootstrap Laravel and handle the request...
(require_once __DIR__.'/../bootstrap/app.php')
->handleRequest(Request::capture());
XRDockerfile
FROM ghcr.io/xrdebug/xrdebug:2.0.2
# Install the 'which' command if it's not already present
RUN apk add --no-cache which
# Create a dummy xdg-open script
RUN echo '#!/bin/sh' > /usr/local/bin/xdg-open && \
echo 'echo "xdg-open called with: $@"' >> /usr/local/bin/xdg-open && \
chmod +x /usr/local/bin/xdg-open
# Set the PATH to include /usr/local/bin
ENV PATH="/usr/local/bin:${PATH}"
compose.json
{
"name": "gopibabus/project-hoa",
"type": "project",
"description": "The application Home Owners in an Association",
"keywords": ["hoa", "home", "owners"],
"license": "MIT",
"require": {
"php": "^8.2",
"laravel/framework": "^11.9",
"laravel/tinker": "^2.9"
},
"require-dev": {
"fakerphp/faker": "^1.23",
"larastan/larastan": "^2.0",
"laravel/horizon": "^5.27",
"laravel/pint": "^1.13",
"laravel/sail": "^1.26",
"laravel/telescope": "^5.2",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.0",
"opcodesio/log-viewer": "^3.11",
"phpunit/phpunit": "^11.0.1",
"xrdebug/php": "^2.0"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi",
"@php -r \"file_exists('database/database.sqlite') || touch('database/database.sqlite');\"",
"@php artisan migrate --graceful --ansi"
],
"tests:unit": "phpunit --testsuite=Unit",
"tests:integration": "phpunit --testsuite=Integration",
"tests:feature": "phpunit --testsuite=Feature",
"analyse:code": "phpstan analyse",
"style:fix": "pint -v",
"style:dryrun": "pint --test"
},
"extra": {
"laravel": {
"dont-discover": ["laravel/telescope"]
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
},
"minimum-stability": "stable",
"prefer-stable": true
}
web.php
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
$var = ["gopi", "sai", "nehalika"];
xr($var, 'Hola, world!');
return view('welcome');
});
I am not getting debug logs on xr dashboard
rodber commented
Use host=host.docker.internal
here: https://github.com/xrdebug/php#configuring
The xrdebug/php client is configured by default for localhost
.