What's the difference between xdebug.ini and php.ini

natral asked
php linux apache xdebug
via

Recently I installed lamp and php-xdebug on an ubuntu 16.04 box. I noticed that now I have the following files

/etc/php/7.0/apache2/conf.d/20-xdebug.ini

/etc/php/7.0/cli/conf.d/20-xdebug.ini

/etc/php/7.0/mods-available/xdebug.ini

I was wandering what is the difference is between these files and settings in /etc/php/7.0/apache2/php.ini are affected by these.

Also in terms of best practice which of these files should be used?

If configurations are repeated in these files with different values which would take precedence?

For example if xdebug.remote_port = 9000 is set in /etc/php/7.0/apache2/php.ini and in /etc/php/7.0/mods-available/xdebug.ini it was set as xdebug.remote_port = 9001 which value would be selected?


Answer
via

This depends on how PHP was compiled. Take a look at how PHP was compiled by reviewing the list of .ini files it is loading and from where they are being loaded.

From the command line, type the following and review:

$ php -i | grep .ini

Or, you can learn of this by creating a temporary PHP file and visiting it in a browser. Just be sure to name it something difficult to find, and delete it right after you’re done; e.g., /info-949w30.php. Why? Because this report may leak full filesystem paths, version numbers, and other details.

<?php phpinfo();

PHP has two directives that are established when it’s compiled.

  • --with-config-file-path=path/to/main.ini
  • --with-config-file-scan-dir=/scan/this/dir/for/other.ini files.

The main .ini file is loaded first, and then files in the scan-dir are loaded alphabetically after that. Which is why you see a lot of .ini files using a numeric prefix. That’s an easy way to take control over the load order. Changing the name of the file in relation to others in the directory.

Share This
Posted in: