Disabling xdebug when running composer

You can disable Xdebug setting an environment variable:

XDEBUG_MODE=off composer install

It's available using XDebug 3.


Update: For Xdebug 3+:

As of Xdebug 3, it is possible to disable the Xdebug completely by setting the option xdebug.mode to off, or by setting the environment variable XDEBUG_MODE=off.

It is very easy to disable Xdebug just for composer, by aliasing composer.

alias composer='XDEBUG_MODE=off \composer'

OR

alias composer='php -dxdebug.mode=off $(where composer | fgrep -v composer: |  head -1)'

You can add the alias to your $HOME/.bashrc to make it permanent.


Update: For Xdebug 1.3 - 3.0.0 :

The issue has been fixed in Composer 1.3. Update composer to the latest version by executing composer self-update, instead of trying the following workaround.


For Xdebug < 1.3

Here is my modification of @ezzatron's code. I have updated the script to detect ini files from phpinfo output.

#!/bin/sh

php_no_xdebug () {
    temporaryPath="$(mktemp -t php.XXXX).ini"

    # Using awk to ensure that files ending without newlines do not lead to configuration error
    php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' | grep -v xdebug > "$temporaryPath"
    
    php -n -c "$temporaryPath" "$@"
    rm -f "$temporaryPath"
}
    
php_no_xdebug /usr/local/bin/composer.phar $@
# On MacOS with composer installed using brew, comment previous line
# Install jq by executing `brew install jq` and uncomment following line.
# php_no_xdebug /usr/local/Cellar/composer/`brew info --json=v1 composer | jq -r '.[0].installed[0].version'`/libexec/composer.phar $@

This command will disable the PHP5 Xdebug module for CLI (and thus composer) :

sudo php5dismod -s cli xdebug

It removes the xdebug.ini symlink from /etc/php5/cli/conf.d/

This was suggested on http://blog.lorenzbausch.de/2015/02/10/php-disable-xdebug-for-cli/

Note that for Ubuntu 16.04 you probably need to run it like this:

sudo phpdismod -s cli xdebug

I don’t think there is an option to configure PHP so it can load different configurations according to the targeted script. At least, not without duplicating .ini files...

However, you can add thoses options when running composer with php:

php -n -d extension=needed_ext.so composer.phar

-n will tell PHP to ignore any php.ini. This will prevent xdebug from loading for this very command.

-d options permits you to add any option you want (for exemple, activate needed_ext.so). You can use multiple -d options. Of course, this is optional, you might not need it.

Then you can create an alias, to make it sugary again.

A typical solution (because composer needs json):

php -n -d extension=json.so composer.phar

greg0ire > my solution, based on that:

#!/bin/bash
options=$(ls -1 /usr/lib64/php/modules| \

    grep --invert-match xdebug| \

    # remove problematic extensions
    egrep --invert-match 'mysql|wddx|pgsql'| \

    sed --expression 's/\(.*\)/ --define extension=\1/'| \

    # join everything together back in one big line
    tr --delete '\n'
)

# build the final command line
php --no-php-ini $options ~/bin/composer $*

alias composer=/path/to/bash/script.sh

It looks ugly (I tried and failed to do that with xargs), but works… I had to disable some extensions though, otherwise I get the following warnings:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysqli.so' - /usr/lib64/php/modules/mysqli.so: undefined symbol: mysqlnd_connect in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_mysql.so' - /usr/lib64/php/modules/pdo_mysql.so: undefined symbol: pdo_parse_params in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/pdo_pgsql.so' - /usr/lib64/php/modules/pdo_pgsql.so: undefined symbol: pdo_parse_params in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/wddx.so' - /usr/lib64/php/modules/wddx.so: undefined symbol: php_XML_SetUserData in Unknown on line 0