Home > Backend Development > PHP Tutorial > PHPStorm配置Xdebug

PHPStorm配置Xdebug

WBOY
Release: 2016-06-20 12:53:00
Original
1186 people have browsed it

本教程适用于Laravel项目的使用者,并默认使用Homestead作为开发环境的虚拟机。

1. 确认你已经安装了Xdebug

通过ssh登录你的homestead,执行

ls /etc/php5/fpm/conf.d
Copy after login

如果你看到20-xdebug.ini的配置项,说明Xdebug是正确加载了的,如下图:

2. 配置xdebug.ini

通过下面的命令进入xdebug.ini所在目录:

cd /etc/php5/mods-available
Copy after login

你可以使用vim对其编辑,在zend_extension=xdebug.so一行下面添加下面几行:

xdebug.remote_enable = onxdebug.remote_connect_back = onxdebug.idekey = "vagrant"
Copy after login

保存,退出,然后重启php-fpm

<br />sudo service php5-fpm restart
Copy after login

3. 配置PHPStorm

在PHPStorm打开你的Laravel项目,按cmd + ,呼出偏好设置,找到PHP下的Servers,进行如下配置:

/path/to/laravel        ==> /home/vagrant/path/to/laravel/path/to/laravel/public ==> /home/vagrant/path/to/laravel/public
Copy after login

这里配置的文件夹根据Homestead.yaml所映射的文件相对应改变。设置完之后,Apply。

然后回到导航栏,找到 Run -> Edit Configurations,添加一个PHP Web Application。如图:

4. 进行测试

在app/routes.php写上一段实例代码:

Route::get('/', function(){    $a = [1, 2, 3, 4, 5];    array_pop($a);});
Copy after login


然后在每一行添加断点,然后Run --> Debug,选择之前设置好的Homestead,如果你看到下图的样子,恭喜你。

Happy Hacking

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template