1
votes

/var/www/html/index.php

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

when index.php is execute in cli mode as below

$ php /var/www/html/index.php

xdebug worked fine enter image description here

However, when execute by apache like

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

nothing happened to xdebug.

Below is the error log of apache, nothing special

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 configured -- resuming normal operations │ qualified domain name, using 10.0.2.15. Set the 'ServerName' dir 2 [Fri Jun 17 05:02:15.526839 2016] [core:notice] [pid 30840] AH00094: Command line: '/usr/sbin/apache2'

I'm using Apache/2.4.7 , PHP/5.5.9 , Ubuntu , vim and DBGPavim in Vagrant virtual machine. How can I find out the reason why xdebug doesn't work via apache?

1
have you configured or enabled xdebug in php.ini? - Chetan Ameta
@ChetanAmeta should be. here's the excerpt of php -i xdebug.remote_autostart => On => On xdebug.remote_connect_back => Off => Off xdebug.remote_cookie_expire_time => 3600 => 3600 xdebug.remote_enable => On => On xdebug.remote_handler => dbgp => dbgp xdebug.remote_host => localhost => localhost xdebug.remote_log => no value => no value xdebug.remote_mode => req => req xdebug.remote_port => 9000 => 9000 and php -m [Zend Modules] Xdebug Zend OPcache - Jarod
it will have 2 php.ini 1 for cli and one for apache, have you configured for both? - Chetan Ameta
@ChetanAmeta you are right. I only configured /etc/php5/cli/php.ini. After configuring /etc/php5/apache2/php.ini xdebug just works well under apache. Thanks a lot. - Jarod

1 Answers

1
votes

After a lot of searching, this is what finally worked for me. Hope this helps !

I'm using PHP 7.0.21, Zend Engine v3.0.0 and Xdebug v2.5.0. I ran the following commands before restarting 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/ && \

My file layout after the fix was

/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

Found this document really helpful.