Saturday, 25 July 2020

how to install xdebug and config with phpstorm in Ubuntu

Follow the https://xdebug.org/docs/install

I try to install Xdebug with PCEL. 

sudo pecl install xdebug

But, it gave me error "phpize" didn't find. 

When I go through the Xdebug website, I know that I need to install PHP development headers. 

So, I type 

sudo apt-get install php-dev

When it's done. I type 

sudo pecl install xdebug 

This time. The system told me "Build process completed successfully"
"Installing '/usr/lib/php/20190902/xdebug.so'
"You should add "zend_extension=/usr/lib/php/20190902/xdebug.so" to php.ini" 

OK. 

type 

sudo find / -name php.ini 

to find out where is my php.ini 

It gave me the result 

/etc/php/7.4/apache2/php.ini  

type

sudo vim /etc/php/7.4/apache2/php.ini

and find out this paragraph 

; If you use constants in your value,  and these constants belong to a 
; dynamically loaded extension (either a PHP extension or a Zend extension),
; you may only use these constants *after* the line that loads the extension. 

add this line 

zend_extension=/usr/lib/php/20190902/xdebug.so

save and quit. 

restart your web server 


If you can see this, means Xdebug installed right. 

  1. config xdebug
Although there have xdebug.ini, but when I open it, I saw it was generated by robot and not suggested modified by hand. And, it was true! Whateven I changed this file, the xdebug config didn't change anything. 

So, I open the php.ini and add a few lines

xdebug.profiler_enable=on #是否启用Xdebug的性能分析,并创建性能信息文件 xdebug.profiler_output_dir="/tmp" #指定性能分析信息文件的输出目录 
xdebug.remote_enable = on #是否开启远程调试 
xdebug.remote_mode=req #指定远程调试模式 
xdebug.remote_host= localhost #指定远程调试的主机名 
xdebug.remote_port = 9000 #指定远程调试的端口号 
xdebug.idekey = PHPSTORM #指定传递给DBGp调试器处理程序的IDE Key

After that, I can check the phpinfo() page. And see, every config info is right. 

配置phpstorm

  1. 配置

以下操作以图片形式展示
选择你自己的php版本

name随便填,自己认得就行,host及端口需要与xdebug.ini中配置的相同,debuger选择xdebug

debug端口也需要与xdebug.ini中配置的相同

2. 验证配置

information栏目全部展示为绿色的勾则表示phpstorm配置成功

安装浏览器xdebug扩展

如果可以翻墙直接去谷歌扩展商店下载安装

如果无法翻墙点击跳转到这个页面 点我 ,然后打开chrome插件目录页将下载的crx文件托进浏览器即可。然后你会发现浏览器菜单栏会出现一个灰色小虫子,鼠标右击它,选择xdebug helper,将ide key变为phpstorm,其实这个在上面xdebug.ini配置中有解释,所以上面那个配置不用填

然后鼠标左击灰色的虫子,将选项由disable变为debug,然后虫子就变为了绿色,这就代表它已经开始工作了,不过你不需要总是打开它,在你调试的域名下将其开启即可。

在phpstorm针对你的项目进行配置

点击phpstorm菜单栏的RUN

在你想打断点的地方点击一下左边的行号一栏,然后将菜单栏的电话由变为两头都是绿色,然后在浏览器中运行你想调试的页面

返回phpstorm点击F9跳到你打断点的地方,F9为跳到下一个断点,F7为下一步,将鼠标移动到下面的选项上即可看到相应的快捷键

调试得到你想要的结果了点击停止即可结束,记得关闭电话,不然会处于调试状态。当你需要再次调试再去打开它。


作者:wenco
链接:https://juejin.im/post/5ba5cba6e51d450e6d00e69f
来源:掘金
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  



No comments:

Post a Comment