150

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.

Gordon
  • 312,688
  • 75
  • 539
  • 559
Beto Aveiga
  • 3,466
  • 4
  • 27
  • 39

27 Answers27

196

Find your php.ini and look for XDebug.

Set xdebug autostart to false

xdebug.remote_autostart=0  
xdebug.remote_enable=0

Disable your profiler

xdebug.profiler_enable=0

Note that there can be a performance loss even with xdebug disabled but loaded. To disable loading of the extension itself, you need to comment it in your php.ini. Find an entry looking like this:

zend_extension = "/path/to/php_xdebug.dll"

and put a ; to comment it, e.g. ;zend_extension = ….

Check out this post XDebug, how to disable remote debugging for single .php file?

rjb
  • 9,036
  • 2
  • 44
  • 49
Uday Sawant
  • 5,748
  • 3
  • 32
  • 45
  • Thanks! I found that my problem was APC, my memory was low apparently. You are right, xdebug is part of PHP, not a module of Apache. Now everything is running fine. – Beto Aveiga Jan 06 '12 at 09:21
  • 1
    @Uday and what if I can't find any of this in my php.ini. I've checked everywhere inside /etc/php including with grep search. – Haralan Dobrev Mar 15 '13 at 10:03
  • 1
    @HaralanDobrev Check phpinfo() to see if xdebug is actually enabled. if it is, check if you have any additional ini files attached to php.ini file. Additionally make sure you are editing correct ini file. it is possible to have these files at multiple locations. – Uday Sawant Mar 15 '13 at 11:01
  • 18
    @UdaySawant I was able to disable it after commenting the line `zend_extension=/usr/lib/php5/20090626+lfs/xdebug.so` from `/etc/php5/conf.d/xdebug.ini`. However neither in `/usr/lib/php5` nor in `/etc` the lines specified in the answer are available. – Haralan Dobrev Mar 15 '13 at 14:58
  • 7
    Actually, it's better to not load the extension at all, and only load it, if needed. XDebug actually slows things down a lot, even if disabled. One might not feel performance has degraded that much, when debugging/profiling some scripts that create a web page, but with daemon scripts, it shows a lot. I just wrote a blog post on why not loading it at all, is better, here: http://bit.ly/14SaWpp – thesilentman Aug 18 '13 at 10:24
  • @thesilentman I read your blog post. Need to test this on my own. Just for a cross check, EasyPHP uses two separate files one for web pages (apache) and one for console apps. Hope you have edited correct ini file. – Uday Sawant Aug 19 '13 at 07:09
  • @UdaySawant Hmm... In my installation (dev 13.1) there's only one ini. The one in runningversion (for the active version) folder. However every time I changed something, I also did a php -i to check. BTW, the testfiles are in this gist:https://gist.github.com/frankmayer/6268139 I've updated the Blog post accordingly – thesilentman Aug 19 '13 at 11:48
  • Thats not the full solution for me... see here which Flag was missing: http://stackoverflow.com/a/30189745/1256697 – suther Nov 11 '15 at 11:16
  • That no longer is the correct answer. See mine down below. – theking2 Jul 19 '22 at 11:56
103

An easy solution working on Linux distributions similar to Ubuntu

sudo php5dismod xdebug
sudo service apache2 restart
guillaumepotier
  • 7,369
  • 8
  • 45
  • 72
Arvi Võime
  • 1,057
  • 1
  • 7
  • 2
48

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
kkochanski
  • 2,178
  • 23
  • 28
27

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

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

Zack Katz
  • 1,310
  • 11
  • 9
14

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.

Sinan Eldem
  • 5,564
  • 3
  • 36
  • 37
11

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');
antonpinchuk
  • 443
  • 4
  • 9
  • In order to really disable XDebug completely, this one is the correct answer, see my comment in @UdaySawant's answer. – thesilentman Aug 18 '13 at 10:27
9

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

sudo rm /etc/php5/cli/conf.d/*xdebug*
Artistan
  • 1,982
  • 22
  • 33
  • note: this really helped me out for composer updates. needed to disable xdebug for performance issues. – Artistan May 08 '14 at 13:11
  • 3
    this works for laravel homestead, too. to disable xdebug in homestead / laravel simply comment out the section in the file `/etc/php5/cli/conf.d/20-xdebug.ini` – ulkas Oct 14 '14 at 08:41
  • Worth mentioning if you run php script from terminal that runs another php script from terminal via `passthru` function with xdebug enabled, xdebug might hang and stop the execution. – Gherman Apr 09 '15 at 08:14
  • 1
    Not sure what the downvote was for, this appears to be the only way to disable xdebug for the CLI and not other environments. Although I'd use `unlink` over `rm` if it's available. – Andy Feb 05 '16 at 00:03
  • 4
    I wouldn't rm/unlink the ini, instead do as ulkas suggested, `sudo nano /etc/php/7.0/cli/conf.d/20-xdebug.ini` and comment it out. – Justin Jun 02 '16 at 16:02
8

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.

Vladimir Vukanac
  • 944
  • 16
  • 29
8

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
Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
7

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

Andrew Atkinson
  • 4,103
  • 5
  • 44
  • 48
7

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

max4ever
  • 11,909
  • 13
  • 77
  • 115
  • 1
    All the other solutions about faffing with filesystem and then this. :raised_hands: True legend! This will even work in a `docker exec` and `docker run`. – MrMesees May 27 '21 at 07:31
  • 1
    for xdebug 3, use `xdebug.mode=off` or, in this case `-dxdebug.mode=off` – Sandra Aug 04 '22 at 08:20
7

Since xdebug 3 came out the settings in pnp.ini have slightly changed. Setting:

xdebug.mode=off

Will disable all processing According to the docs:

Nothing is enabled. Xdebug does no work besides checking whether functionality is enabled. Use this setting if you want close to 0 overhead.

theking2
  • 2,174
  • 1
  • 27
  • 36
5

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.

Sumoanand
  • 8,835
  • 2
  • 47
  • 46
5

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
Shadab Salam
  • 61
  • 1
  • 5
5

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.

Justin
  • 26,443
  • 16
  • 111
  • 128
  • Is is not a solution, because /etc/php/7.0/cli/conf.d/20-xdebug.ini is just a symlink and if you edit it, you edit the original file which is common for cli and non-cli. I think the right solution is simple delete the symlink. – igoemon Sep 03 '16 at 18:37
  • Updated answer ^. – Justin Oct 21 '16 at 14:26
5

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
Firze
  • 3,939
  • 6
  • 48
  • 61
  • Very helpful script. You could mention that a service restart is required for the changes to take effect, which isn't immediately obvious (at least, it was required for my system). – Katai Sep 02 '22 at 08:13
5

You can disable Xdebug on PHP CLI on runtime using the -d flag:

php -d xdebug.mode=off -i | grep xdebug.mode

Result: xdebug.mode => off => off

Example, running unit tests with Xdebug disabled, so it's faster:

php -d xdebug.mode=off ./vendor/bin/phpunit

You can also create an alias for it to make it easier to use.

Lucas Bustamante
  • 15,821
  • 7
  • 92
  • 86
4

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.

jerrymouse
  • 16,964
  • 16
  • 76
  • 97
4

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.

suther
  • 12,600
  • 4
  • 62
  • 99
4

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

crmpicco
  • 16,605
  • 26
  • 134
  • 210
3

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
alvaro.canepa
  • 562
  • 3
  • 13
2

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

Casper André Casse
  • 573
  • 2
  • 8
  • 20
2

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

Kirby
  • 2,847
  • 2
  • 32
  • 42
2

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.

bantya
  • 576
  • 11
  • 23
2

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
Jim
  • 41
  • 4
1

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!

Reinherd
  • 5,476
  • 7
  • 51
  • 88
0

In CLI:

sudo phpdismod xdebug

disable xdebug

sudo phpenmod xdebug

enable xdebug

And restart the server