WSL中Ubuntu24安装Php的Xdebug
$ sudo apt install php8.4-xdebug
[sudo] password for yang:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
libllvm19
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
php8.4-xdebug
0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded.
Need to get 687 kB of archives.
After this operation, 2114 kB of additional disk space will be used.
Get:1 https://ppa.launchpadcontent.net/ondrej/php/ubuntu noble/main amd64 php8.4-xdebug amd64 3.4.5-1+ubuntu24.04.1+deb.sury.org+1 [687 kB]
Fetched 687 kB in 3s (253 kB/s)
Selecting previously unselected package php8.4-xdebug.
(Reading database ... 47819 files and directories currently installed.)
Preparing to unpack .../php8.4-xdebug_3.4.5-1+ubuntu24.04.1+deb.sury.org+1_amd64.deb ...
Unpacking php8.4-xdebug (3.4.5-1+ubuntu24.04.1+deb.sury.org+1) ...
Setting up php8.4-xdebug (3.4.5-1+ubuntu24.04.1+deb.sury.org+1) ...
Processing triggers for libapache2-mod-php8.4 (8.4.12-1+ubuntu24.04.1+deb.sury.org+1) ...
Processing triggers for php8.4-fpm (8.4.12-1+ubuntu24.04.1+deb.sury.org+1) ...
NOTICE: Not enabling PHP 8.4 FPM by default.
NOTICE: To enable PHP 8.4 FPM in Apache2 do:
NOTICE: a2enmod proxy_fcgi setenvif
NOTICE: a2enconf php8.4-fpm
NOTICE: You are seeing this message because you have apache2 package installed.
Processing triggers for php8.4-cli (8.4.12-1+ubuntu24.04.1+deb.sury.org+1) ...
yang@DESKTOP-C6K4RMT:/var/www/html$ php -m | grep xdebug
xdebug
yang@DESKTOP-C6K4RMT:/var/www/html$ php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
random
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Xdebug
Zend OPcache
查找php.ini
$ php --ini
Configuration File (php.ini) Path: /etc/php/8.4/cli
Loaded Configuration File: /etc/php/8.4/cli/php.ini
Scan for additional .ini files in: /etc/php/8.4/cli/conf.d
Additional .ini files parsed: /etc/php/8.4/cli/conf.d/10-mysqlnd.ini,
/etc/php/8.4/cli/conf.d/10-opcache.ini,
E$ cd /etc/php/8.4/fpm/
yang@DESKTOP-C6K4RMT:/etc/php/8.4/fpm$ ls -al
total 92
drwxr-xr-x 4 root root 4096 Sep 12 19:53 .
drwxr-xr-x 6 root root 4096 Sep 12 19:53 ..
drwxr-xr-x 2 root root 4096 Sep 17 10:41 conf.d
-rw-r--r-- 1 root root 5427 Aug 29 14:48 php-fpm.conf
-rw-r--r-- 1 root root 69369 Aug 29 14:48 php.ini
drwxr-xr-x 2 root root 4096 Sep 17 09:00 pool.d
yang@DESKTOP-C6K4RMT:/etc/php/8.4/fpm$
找到加载的 php.ini 文件,并确保包含类似以下配置:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=192.168.1.118 #windows主机的ip
xdebug.client_port=9003
xdebug.idekey=PHPSTORM
xdebug.start_with_request=yes
xdebug.log=/tmp/xdebug //查看异常日志
xdebug.log_level =10