要在 PhpStorm 中远程调试 CentOS 项目,请按照以下步骤操作:
在 CentOS 服务器上,使用以下命令安装 Xdebug:
sudo yum install php-xdebug
编辑你的 php.ini
文件(通常位于 /etc/php.ini
或 /etc/php/7.x/cli/php.ini
),添加以下配置:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=<your_local_ip>
xdebug.client_port=9003
xdebug.start_with_request=yes
将 <your_local_ip>
替换为你的本地计算机 IP 地址。保存并关闭文件。
重启你的 Web 服务器(例如 Apache 或 Nginx)以应用更改:
sudo systemctl restart httpd
或
sudo systemctl restart nginx
打开 PhpStorm,然后转到 “File” > “Settings” > “Languages & Frameworks” > “PHP”。在 “CLI Interpreter” 部分,点击齿轮图标,然后选择 “Add”。输入一个名称,选择 “SSH Interpreter”,然后输入你的 CentOS 服务器的 IP 地址、用户名和密码。
在 “Interpreter” 部分,选择 “Path to PHP executable”。这应该是你的 CentOS 服务器上的 PHP 可执行文件路径,例如 /usr/bin/php
。在 “Additional Options” 部分,添加以下参数:
-xdebug.start_with_request=yes
-xdebug.client_host=<your_local_ip>
-xdebug.client_port=9003
将 <your_local_ip>
替换为你的本地计算机 IP 地址。点击 “Finish” 以保存设置。
在你的项目中设置断点,以便在调试时暂停执行。
在 PhpStorm 中,转到 “Run” > “Start Listening for PHP Debug Connections”。然后,在你的浏览器中访问你的 CentOS 项目。当代码执行到断点时,PhpStorm 将捕获并显示调试信息。
使用 PhpStorm 的调试工具栏来逐步执行代码、查看变量值等。
完成调试后,转到 “Run” > “Stop Listening for PHP Debug Connections” 以停止调试会话。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>