我正在尝试在 Linux Ubuntu 操作系统上调试我的 Laravel 项目,因此我配置了 Xdebug,但它的断点不侦听传入的请求。
当我运行
phpinfo();
时,Xdebug 已正确启用,但当我从 VSCode IDE 中监听时,它不起作用。
这是我的 Docker 撰写文件
version: '3.8'
services:
app:
container_name: app
build:
context: .
dockerfile: .docker/php/Dockerfile
volumes:
- .:/var/www/html
- .docker/php/conf.d/local.ini:/usr/local/etc/php/conf.d/local.ini
- .docker/php/conf.d/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
- .docker/php/conf.d/error_reporting.ini:/usr/local/etc/php/conf.d/error_reporting.ini
extra_hosts:
- "host.docker.internal:host-gateway"
mem_limit: 1024m
mem_reservation: 512M
depends_on:
- mysql
networks:
- app-network
server:
image: nginx:alpine
container_name: server
restart: unless-stopped
tty: true
ports:
- "8000:80"
dns:
- 8.8.8.8
- 4.4.4.4
volumes:
- .:/var/www/html
- .docker/nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
应用程序(php)Dockerfile内容:
FROM php:8.1.18-fpm
WORKDIR /var/www/html
COPY --chown=www-data:www-data . /var/www/html
RUN apt-get update -y && apt-get install -y curl zip unzip sendmail libpng-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
default-mysql-client \
net-tools \
inetutils-ping \
netcat \
&& docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ \
&& docker-php-ext-install gd
RUN apt-get install -y git
RUN apt-get install -y zip libzip-dev \
&& docker-php-ext-configure zip \
&& docker-php-ext-install zip \
&& docker-php-ext-install exif && docker-php-ext-enable exif
RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN docker-php-ext-enable mysqli pdo pdo_mysql
RUN docker-php-ext-install pcntl
RUN pecl install -o -f xdebug \
&& docker-php-ext-enable xdebug
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
关于nginx配置
server {
listen 0.0.0.0:80;
index index.php index.html;
root /var/www/html/public;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
# Enable CORS Preflighted requests
if ($request_method = OPTIONS ) {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' '*';
add_header 'Access-Control-Allow-Headers' '*';
return 204;
}
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
gzip_static on;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
这是 xdebug.ini 配置内容:
zend_extension=xdebug
[xdebug]
xdebug.mode = debug,develop
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.start_with_request=yes
xdebug.discover_client_host=1
xdebug.extended_info=1
xdebug.log=/tmp/xdebug.log
xdebug.idekey=VSCODE ; can also be phpstorm
;; ------------------------------------
;; Color var_dumps when in CLI
xdebug.cli_color=1
这是我的 VSCode 中 Xdebug 的
launch.json
文件内容:
{
// 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/html": "${workspaceFolder}"
}
}
]
}
这是我的
phpinfo()
的示例图像:
不知道您是否找到了这个问题的原因?