虚拟机安装PHP
先下载一个Linux镜像,我选择Ubuntu镜像server版
基于上述镜像添加虚拟机,按提示填写地区和用户信息
登录服务器安装远程连接软件
#安装ssh服务 apt install openssh-server systemctl start ssh ufw allow 22 #virtual box添加端口映射2222->22
虚拟机添加共享文件夹
D:\VirtualBox VMs\php8.4\share
,共享名sharephp840
,共享到/home/xiao/share
xiao# sudo mount -t vboxsf sharephp840 ./share xiao# vim /etc/fstab # 添加 sharephp840 /home/xiao/share vboxsf defaults 0 0
下载php源码拷贝到共享文件夹
tar -zxvf php-8.4.0.tar.gz sudo apt update sudo apt install build-essential libxml2-dev libssl-dev libcurl4-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libzip-dev libsqlite3-dev ./configure --prefix=/home/codes/php/php-8.4.0/output/ --enable-fpm --enable-debug CFLAGS="-g3 -O0"# -g3 保留宏信息,-O0 禁用优化 make make install
配置vscode
安装Remote-SSH扩展
按住ctrl+shift+p打开命令面板,找到remote-ssh:connect to host…,输入上述虚拟机连接信息,连接成功后打开虚拟机上的PHP源码目录。
在vscode侧边栏,点击run and debug,创建一个launch.json,添加配置信息如下:
{ "version": "0.2.0", "configurations": [ { "name": "Debug PHP Core", "type": "cppdbg", "request": "launch", "program": "/home/codes/php/php-8.4.0/output/bin/php", "args": [ "/home/xiao/share/php/array.php" ], "cwd": "/home/xiao/share/php-8.4.0", "environment": [], "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ] } ] }
下面就可以在php源码设置断点调试了