[php] How to disable XDebug

I think that my server became slow since I installed XDebug. So, in order to test my hypothesis I want to disable XDebug completely. I've been searching for tutorials on how to do this but I can't find such information.

This question is related to php xdebug apc

The answer is


(This is for CentOS)

Rename the config file and restart apache.

sudo mv /etc/php.d/xdebug.ini /etc/php.d/xdebug.ini.old
sudo service httpd restart

Do the reverse to re-enable.


Comment extension in php.ini and restart Apache. Here is a simple script (you can assign shortcut to it)

xdebug-toggle.php

define('PATH_TO_PHP_INI', 'c:/xampp/php/php.ini');
define('PATH_TO_HTTPD', 'c:/xampp/apache/bin/httpd.exe');
define('REXP_EXTENSION', '(zend_extension\s*=.*?php_xdebug)');

$s = file_get_contents(PATH_TO_PHP_INI);
$replaced = preg_replace('/;' . REXP_EXTENSION . '/', '$1', $s);
$isOn = $replaced != $s;
if (!$isOn) {
    $replaced = preg_replace('/' . REXP_EXTENSION . '/', ';$1', $s);
}
echo 'xdebug is ' . ($isOn ? 'ON' : 'OFF') . " now. Restarting apache...\n\n";
file_put_contents(PATH_TO_PHP_INI, $replaced);

passthru(PATH_TO_HTTPD . ' -k restart');

So, yeah, all what you need, just comment line in INI file like zend_extension=xdebug.so or similar.

Comments can be made by adding semicolon.

But, such kind of answer already added, and I'd like to share ready solution to switch Xdebug status.

I've made quick switcher for Xdebug. Maybe it would be useful for someone.

Xdebug Switcher


Find your PHP.ini and look for XDebug.

normally in Ubuntu its path is

/etc/php5/apache2/php.ini  

Make following changes (Better to just comment them by adding ; at the beginning )

xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.profiler_enable=0

then restart your server again for Ubuntu

sudo service apache2 restart

In Linux Ubuntu(maybe also another - it's not tested) distribution with PHP 5 on board, you can use:

sudo php5dismod xdebug

And with PHP 7

sudo phpdismod xdebug

And after that, please restart the server:

sudo service apache2 restart

Inspired by PHPStorm right click on a file -> debug -> ...

www-data@3bd1617787db:~/symfony$ 
php 
-dxdebug.remote_enable=0 
-dxdebug.remote_autostart=0 
-dxdebug.default_enable=0 
-dxdebug.profiler_enable=0 
test.php

the important stuff is -dxdebug.remote_enable=0 -dxdebug.default_enable=0


For those interested in disabling it in codeship, run this script before running tests:

rm -f /home/rof/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini

I was receiving this error:

Use of undefined constant XDEBUG_CC_UNUSED - assumed 'XDEBUG_CC_UNUSED' (this will throw an Error in a future version of PHP)

which is now gone!


On Windows (WAMP) in CLI ini file:

X:\wamp\bin\php\php5.x.xx\php.ini

comment line

; XDEBUG Extension

;zend_extension = "X:/wamp/bin/php/php5.x.xx/zend_ext/php_xdebug-xxxxxx.dll"

Apache will process xdebug, and composer will not.


I created this bash script for toggling xdebug. I think it should work at least on Ubuntu / Debian. This is for PHP7+. For PHP5 use php5dismod / php5enmod.

#!/bin/bash

#
# Toggles xdebug
#

if [ ! -z $(php -m | grep "xdebug") ] ; then
    phpdismod xdebug
    echo "xdebug is now disabled"
else
    phpenmod xdebug
    echo "xdebug is now enabled"
fi

# exit success
exit 0

If you are using MAMP Pro on Mac OS X it's done via the MAMP client by unchecking Activate Xdebug under the PHP tab:

Disabling Xdebug in MAMP Pro


in xubuntu I totally disabled xdebug for the CLI with this...

sudo rm /etc/php5/cli/conf.d/*xdebug*

Ubuntu 16.04 remove xdebug from PHP.

Find your php.ini file and make sure xdebug is there:

grep -r "xdebug" /etc/php/

This might come up with different versions, if so run php -v to find your version.

Edit the php.ini file, like:

sudo vi /etc/php/5.6/mods-available/xdebug.ini

Comment the line:

//zend_extension=xdebug.so

Save the file


Disable xdebug only for certain PHP version or sapi. On this case PHP 7.2 fpm

sudo phpdismod -v 7.2 -s fpm xdebug
sudo service php7.2-fpm nginx restart

I had following Problem: Even if I set

xdebug.remote_enable=0 

Xdebug-Error-Message-Decoration was shown.

My solution:

xdebug.default_enable=0

Only if I use this Flag, Xdebug was disabled.


Disable xdebug

For PHP 7: sudo nano /etc/php/7.0/cli/conf.d/20-xdebug.ini

For PHP 5: sudo nano /etc/php5/cli/conf.d/20-xdebug.ini

Then comment out everything and save.


UPDATE -- Disable for CLI only

As per @igoemon's comment, this is a better method:

PHP 7.0 (NGINX)

sudo mv /etc/php/7.0/cli/conf.d/20-xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.ini.old
sudo service nginx restart

Note: Update the path to your version of PHP.


I renamed the config file and restarted server:

$ mv /etc/php/7.0/fpm/conf.d/20-xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini.bak

$ sudo service php7.0-fpm restart && sudo service nginx restart

It did work for me.


If you are using php-fpm the following should be sufficient:

sudo phpdismod xdebug
sudo service php-fpm restart

Notice, that you will need to tweak this depending on your php version. For instance running php 7.0 you would do:

sudo phpdismod xdebug
sudo service php7.0-fpm restart

Since, you are running php-fpm there should be no need to restart the actual webserver. In any case if you don't use fpm then you could simply restart your webserver using any of the below commands:

sudo service apache2 restart
sudo apache2ctl restart

Two options:

1: Add following code in the initialization Script:

 if (function_exists('xdebug_disable')) {
           xdebug_disable();
         }

2: Add following flag to php.ini

 xdebug.remote_autostart=0
 xdebug.remote_enable=0

1st option is recommended.


I ran into a similar issue. Sometimes, you wont find xdebug.so in php.ini. In which case, execute phpinfo() in a php file and check for Additional .ini files parsed. Here you'll see more ini files. One of these will be xdebug's ini file. Just remove (or rename) this file, restart apache, and this extension will be removed.


An easy solution working on Linux distributions similar to Ubuntu

sudo php5dismod xdebug
sudo service apache2 restart

Also, you can add xdebug_disable() to your code. Try:

if(function_exists('xdebug_disable')) { xdebug_disable(); }


For WAMP, click left click on the Wamp icon in the taskbar tray. Hover over PHP and then click on php.ini and open it in your texteditor.

Now, search for the phrase 'zend_extension' and add ; (semicolon) in front it.

Restart the WAMP and you are good to go.


Apache/2.4.33 (Win64) PHP/7.2.4 myHomeBrew stack

At end of php.ini I use the following to manage Xdebug for use with PhpStorm

; jch ~ Sweet analizer at https://xdebug.org/wizard.php for matching xdebug to php version.
; jch ~ When upgrading php versions check if newer xdebug.dll is needed in ext directory.
; jch Renamed... zend_extension = E:\x64Stack\PHP\php7.2.4\ext\php_xdebug-2.6.0-7.2-vc15-x86_64.dll

zend_extension = E:\x64Stack\PHP\php7.2.4\ext\php_xdebug.dll

; jch !!!! Added the following for Xdebug with PhpStorm

[Xdebug]
; zend_extension=<full_path_to_xdebug_extension>
; xdebug.remote_host=<the host where PhpStorm is running (e.g. localhost)>
; xdebug.remote_port=<the port to which Xdebug tries to connect on the host where PhpStorm is running (default 9000)>

xdebug.remote_enable=1
xdebug.remote_host=localhost
xdebug.remote_port=9000

xdebug.profiler_enable=1
xdebug.profiler_output_dir="E:\x64Stack\Xdebug_profiler_output"
xdebug.idekey=PHPSTORM
xdebug.remote_autostart=1

; jch ~~~~~~~~~To turn Xdebug off(disable) uncomment the following 3 lines restart Apache~~~~~~~~~ 
;xdebug.remote_autostart=0  
;xdebug.remote_enable=0
;xdebug.profiler_enable=0

; !!! Might get a little more speed by also commenting out this line above... 
;;; zend_extension = E:\x64Stack\PHP\php7.2.4\ext\php_xdebug.dll
; so that Xdebug is both disabled AND not loaded