Home  >  Article  >  Backend Development  >  Centos下PHP配置xdebug

Centos下PHP配置xdebug

WBOY
WBOYOriginal
2016-06-20 12:38:33957browse

首先需要下载xdebug,我们可以 点此 下载xdebug-2.2.5.tgz,或者在 xdebug官网 下载相应的安装包。并且确定PHP的安装目录,假设php安装目录为/usr/local/php。

安装xdebug

对于xdebug可以独立于PHP进行编译安装,但是我们必须拥有执行phpize的权限,并且对于php-config也拥有相应的权限,此二者所在目录为

/usr/local/php/bin/phpize/usr/local/php/bin/php-config

接下来按照以下步骤安装xdebug

1. # tar –zxvf xdebug-2.2.5.tg //解压源码包,但是需要注意的是没有必要把源码解压到PHP的源码包中,解压到独立的目录

2. # cd xdebug-2.2.5  //进入源码目录中

3. Xdebug]# /usr/local/php/bin/phpize //运行phpize命令,运行此命令以后会在源码目录中产生configure等文件

4. Xdebug]# ./configure –enable-xdebug –with-php-config=/usr/local/php/bin/php-config  //配置xdebug

5. Xdebug]# make && make install  //编译安装

在第四步中的选项 –with-php-config不能省略,如果我们省略了此选项,那么有可能会报如下错误

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure: error: Cannot find php-config. Please use --with-php-config=PATH

按照上述步骤安装,如果没有什么特殊情况的话安装会顺利的进行,最后出现如下结果表示安装成功

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/

+----------------------------------------------------------------------+

|                                                                      |

|   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.                                                            |

|                                                                      |

+----------------------------------------------------------------------+

配置PHP 使其支持xdebug

按照上述最后的显示结果,说明xdebug已经安装成功,并且我们需要对php.ini文件进行配置,打开php.ini文件

# vim /usr/local/php/etc/php.ini   //打开php.ini文件

在文件中添加如下几行

zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so

[Xdebug]

xdebug.remote_enable = 1   //开启远程调试

xdebug.remote_host = 192.168.18.228 //远程ip地址抑或是本机地址

xdebug.remote_port = 9000  //远程IDE服务器监听端口

xdebug.remote_handler=DBGP  //使用的协议

(除此之外,xdebug选项的详细解释请参考 xdebug所有设置说明 )

添加完以后,保存退出。如果PHP环境使用的是SAPIs方式,那我们需要重启Web服务器;如果使用的是FastCGI的方式那我们需要重启php-fpm。重启完以后,新建php脚本使用phpinfo()查看php的配置如下图

说明PHP配置xdebug成功。

Statement:
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