ubuntu + phpStorm + Xdebug安装及调试设置

1、下载Xdebug

点击下载

2、安装

1、接下源码
1
tar zxvf xdebug.tar.gz
2、编译源码
1
2
3
4
5
cd xdebug
/usr/local/php/bin/phpize
./configure --enable-xdebug --with-php-config=/usr/local/php/bin/php-config
make
make install

安装完成后会出现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
+----------------------------------------------------------------------------------------------------+
|
| INSTALLATION INSTRUCTIONS
| =========================
|
| See http://xdebug.org/install.php#configure-php for instructions
| on how to enable Xdebug for PHP.
|
| Documentation is available online as well:
| - A list of all settings: http://xdebug.org/docs-settings.php
| - A list of all functions: http://xdebug.org/docs-functions.php
| - Profiling instructions: http://xdebug.org/docs-profiling2.php
| - Remote debugging: http://xdebug.org/docs-debugger.php
|
|
| NOTE: Please disregard the message
| You should add "extension=xdebug.so" to php.ini
| that is emitted by the PECL installer. This does not work for
| Xdebug.
|
+----------------------------------------------------------------------------------------------------+
3、修改配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sudo vim php.ini
#加一下内容
[Xdebug]
zend_extension=/usr/local/php5.6/lib/php/extensions/no-debug-non-zts-20131226/xdebug.so
xdebug.idekey = PHPSTORM
xdebug.auto_trace = on
xdebug.default_enable = on
xdebug.auto_profile = on
xdebug.collect_params = on
xdebug.collect_return = on
xdebug.profiler_enable = on
xdebug.remote_enable = 1
xdebug.remote_host = 192.168.1.225
xdebug.remote_port = 9059
xdebug.remote_handler = dbgp
xdebug.remote_connect_back = 1
xdebug.trace_output_dir = "/usr/local/php/xdebug/"
xdebug.profiler_output_dir = "/usr/local/php/xdebug/"

重启lnmp后通过php -v应该可以看到

1
2
3
4
5
PHP 5.4.45 (cli) (built: Jan 19 2018 10:30:47)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
with Zend Guard Loader v3.3, Copyright (c) 1998-2013, by Zend Technologies

4、安装火狐xdebug插件

下载插件地址

安装完毕之后, 打开该插件的options, 设置IDEKey为PhpStorm.

需要和phpstorm中设置的ide key 保持一致

5、phpstorm的设置

6、开始进行断点测试,断点测试前,可以进行xdebug的验证是否配置成功

第一个地址栏填写你的项目的地址

第二个地址栏填写你访问的地址

点击validate开始验证,若有错误,根据提示修改配置。

7、点击phpstorm小电话图标,开始监听,设置断点并并调试。

原理示意图(从xdebug的官网上引用的)

Debian或Ubuntu运行php5-fpm报错connect() to unix:/var/run/php5-fpm.sock

在ubuntu12.04中安装配置LNMP时 出现在php5-fpm的错误

1
2
3
4
5
6
7
8
2013/04/26 04:01:05 [crit] 6119#0:
 *4 connect() to unix:/var/run/php5-fpm.sock failed
(2: No such file or directory) while connecting to upstream,
client: 159.53.110.141,
server: 216.238.88.42,
request: "GET / HTTP/1.1",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:",
host: "216.238.88.42:9090

nginx中是这样配置的

1
2
3
4
5
6
7
8
9
10
11
location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

    # With php5-cgi alone:
    fastcgi_pass 127.0.0.1:9000;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

我个人的配置是想用sock的方法 毕竟sock方式对于高并发来说 还是比使用cgi方式好的
问题其实出现在 fastcgi_pass得配置上面。在ubuntu 12.10安装了php5-fpm之后。我们可以去

1
/etc/php5/fpm/pool.d/www.conf

里面找到这样一段代码:

1
listen = 127.0.0.1:9000

在这上面代码的下面添加一行:

1
listen = /var/run/php5-fpm.sock

保存后启动php5-fpm

1
/etc/init.d/php5-fpm restart

这时就可以正常访问了

另外有可能是sock文件的执行权限有问题,对sock文件执行

1
chmod 777 php5-fpm.sock

再启动php5-fpm问题解决。