为什么xdebug不能在apache中工作

时间:2016-06-17 05:34:40

标签: php apache xdebug

/var/www/html/index.php

<?php
   echo 'a';
   echo 'a';

当index.php在cli模式下执行时,如下所示

$ php /var/www/html/index.php
xdebug工作正常 enter image description here

然而,当由apache执行时如

$ curl 'http://localhost:80?XDEBUG_SESSION_START=1'
aa

xdebug没有发生任何事情。

以下是apache的错误日志,没什么特别的

  

1 [Fri Jun 17 05:02:15.526773 2016] [mpm_prefork:notice] [pid 30840] AH00163:Apache / 2.4.7(Ubuntu)PHP / 5.5.9-1ubuntu4.17已配置 - 恢复正常操作│合格的域名,使用10.0.2.15。设置&#39; ServerName&#39; DIR     2 [Fri Jun 17 05:02:15.526839 2016] [core:notice] [pid 30840] AH00094:命令行:&#39; / usr / sbin / apache2&#39;

我在Vagrant虚拟机中使用Apache / 2.4.7,PHP / 5.5.9,Ubuntu,vim和DBGPavim。 我怎样才能找出xdebug无法通过apache工作的原因?

1 个答案:

答案 0 :(得分:1)

我是PHP的新手,但经过大量搜索,这终于对我有用。希望这可以帮助 !

我正在使用PHP 7.0.21,Zend Engine v3.0.0和Xdebug v2.5.0。在重新启动apache之前,我运行了以下命令

# Step 1 : In xdebug.ini or php.ini enable xdebug
sed -i 's/;zend_extension=xdebug.so/zend_extension=xdebug.so/' /etc/php7/conf.d/xdebug.ini
echo -e "xdebug.remote_enable=1\nxdebug.remote_handler=dbgp\nxdebug.remote_mode=req\nxdebug.remote_host=127.0.0.1\nxdebug.remote_port=9000" >> /etc/php7/conf.d/xdebug.ini

# Step 2: Copy the php + xdebug configuration files to apache
cp /etc/php7/php.ini /etc/apache2/ && \
cp /usr/lib/php7/modules/xdebug.so /usr/lib/apache2 && \
cp /etc/php7/conf.d/xdebug.ini /etc/apache2/conf.d/ && \

修复后我的文件布局为

/etc
|--php7
|     |-- php.ini
|     |-- conf.d
|              |-- xdebug.ini
|--apache2
|     |--php.ini
|     |-- conf.d
|              |-- xdebug.ini


/usr/lib
|--php7
|    |--modules
|          |--xdebug.so
|--apache2
|    |--modules
|          |--xdebug.so

找到this文档确实很有帮助。