title: PHP7 CLI attempts to load xdebug twice - "Cannot load Xdebug - it was already loaded"
body: <p>After upgrading Ubuntu from 14.04 to 16.04, PHP CLI started complaining about xdebug:</p>
  
  <pre><code>$ php -v
  Cannot load Xdebug - it was already loaded
  PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )
  Copyright (c) 1997-2016 The PHP Group
  Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
      with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies
      with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
  </code></pre>
  
  <p>There is only one .ini file:</p>
  
  <pre><code>$ ls -la /etc/php/7.0/cli/conf.d/ | grep xdebug
  lrwxrwxrwx 1 root root   38 Jan 19 11:41 20-xdebug.ini -&gt; /etc/php/7.0/mods-available/xdebug.ini
  </code></pre>
  
  <p>And it's only referenced once in this output from <code>php -i</code>:</p>
  
  <pre><code>$ php -i | grep -i configuration
  Cannot load Xdebug - it was already loaded
  Configuration File (php.ini) Path =&gt; /etc/php/7.0/cli
  Loaded Configuration File =&gt; /etc/php/7.0/cli/php.ini
  Configuration
  </code></pre>
  
  <p>And there's only one reference to xdebug in the entire directory (so it's not being included twice):</p>
  
  <pre><code>/etc/php/7.0$ grep -r xdebug *
  mods-available/xdebug.ini:zend_extension=xdebug.so
  mods-available/xdebug.ini:[xdebug]
  mods-available/xdebug.ini:xdebug.remote_enable=1
  mods-available/xdebug.ini:xdebug.remote_autostart=1
  mods-available/xdebug.ini:xdebug.remote_port=9000
  mods-available/xdebug.ini:xdebug.idekey=PHPSTORM
  </code></pre>
  
  <p>If I do <code>$ phpdismod xdebug</code> I get the following output, suggesting that it still has xdebug loaded:</p>
  
  <pre><code>$ php -v
  PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )
  Copyright (c) 1997-2016 The PHP Group
  Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
      with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies
      with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
  </code></pre>
  
  <p>Having done that it is no longer present in the apache config as shown by <code>phpinfo()</code>. </p>
  
  <p>How do I fix this?</p>
  
  <hr>
  
  <p><em>Edit:</em>  Additional output as requested:</p>
  
  <pre><code>$ php --ini
  Cannot load Xdebug - it was already loaded
  Configuration File (php.ini) Path: /etc/php/7.0/cli
  Loaded Configuration File:         /etc/php/7.0/cli/php.ini
  Scan for additional .ini files in: /etc/php/7.0/cli/conf.d
  Additional .ini files parsed:      /etc/php/7.0/cli/conf.d/10-mysqlnd.ini,
  /etc/php/7.0/cli/conf.d/10-opcache.ini,
  /etc/php/7.0/cli/conf.d/10-pdo.ini,
  /etc/php/7.0/cli/conf.d/15-xml.ini,
  /etc/php/7.0/cli/conf.d/20-bcmath.ini,
  /etc/php/7.0/cli/conf.d/20-calendar.ini,
  /etc/php/7.0/cli/conf.d/20-ctype.ini,
  /etc/php/7.0/cli/conf.d/20-curl.ini,
  /etc/php/7.0/cli/conf.d/20-dom.ini,
  /etc/php/7.0/cli/conf.d/20-exif.ini,
  /etc/php/7.0/cli/conf.d/20-fileinfo.ini,
  /etc/php/7.0/cli/conf.d/20-ftp.ini,
  /etc/php/7.0/cli/conf.d/20-gd.ini,
  /etc/php/7.0/cli/conf.d/20-gettext.ini,
  /etc/php/7.0/cli/conf.d/20-iconv.ini,
  /etc/php/7.0/cli/conf.d/20-json.ini,
  /etc/php/7.0/cli/conf.d/20-mbstring.ini,
  /etc/php/7.0/cli/conf.d/20-mcrypt.ini,
  /etc/php/7.0/cli/conf.d/20-mysqli.ini,
  /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini,
  /etc/php/7.0/cli/conf.d/20-pdo_sqlite.ini,
  /etc/php/7.0/cli/conf.d/20-phar.ini,
  /etc/php/7.0/cli/conf.d/20-posix.ini,
  /etc/php/7.0/cli/conf.d/20-readline.ini,
  /etc/php/7.0/cli/conf.d/20-shmop.ini,
  /etc/php/7.0/cli/conf.d/20-simplexml.ini,
  /etc/php/7.0/cli/conf.d/20-sockets.ini,
  /etc/php/7.0/cli/conf.d/20-sqlite3.ini,
  /etc/php/7.0/cli/conf.d/20-sysvmsg.ini,
  /etc/php/7.0/cli/conf.d/20-sysvsem.ini,
  /etc/php/7.0/cli/conf.d/20-sysvshm.ini,
  /etc/php/7.0/cli/conf.d/20-tokenizer.ini,
  /etc/php/7.0/cli/conf.d/20-wddx.ini,
  /etc/php/7.0/cli/conf.d/20-xdebug.ini,
  /etc/php/7.0/cli/conf.d/20-xmlreader.ini,
  /etc/php/7.0/cli/conf.d/20-xmlwriter.ini,
  /etc/php/7.0/cli/conf.d/20-xsl.ini
  </code></pre>
  
  <hr>
  
  <pre><code>$ cat /etc/php/7.0/mods-available/xdebug.ini 
  zend_extension=xdebug.so
  [xdebug]
  xdebug.remote_enable=1
  xdebug.remote_autostart=1
  xdebug.remote_port=9000
  xdebug.idekey=PHPSTORM
  </code></pre>
  
  <hr>
  
  <p>As this is still an issue I have found some further detail:</p>
  
  <p>Paths:</p>
  
  <pre><code>$ ls -la /usr/bin/php
  lrwxrwxrwx 1 root root 21 Apr 18  2017 /usr/bin/php -&gt; /etc/alternatives/php
  $ ls -la /etc/alternatives/php
  lrwxrwxrwx 1 root root 15 Feb 12 15:43 /etc/alternatives/php -&gt; /usr/bin/php7.1
  </code></pre>
  
  <p>php:</p>
  
  <pre><code>$ php -v
  Cannot load Xdebug - it was already loaded
  PHP 7.1.15-1+ubuntu16.04.1+deb.sury.org+2 (cli) (built: Mar  6 2018 11:10:13) ( NTS )
  Copyright (c) 1997-2018 The PHP Group
  Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
      with Zend OPcache v7.1.15-1+ubuntu16.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies
      with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
  </code></pre>
  
  <p>php7.1:</p>
  
  <pre><code>$ php7.1 -v
  PHP 7.1.15-1+ubuntu16.04.1+deb.sury.org+2 (cli) (built: Mar  6 2018 11:10:13) ( NTS )
  Copyright (c) 1997-2018 The PHP Group
  Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
      with Zend OPcache v7.1.15-1+ubuntu16.04.1+deb.sury.org+2, Copyright (c) 1999-2018, by Zend Technologies
      with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
  </code></pre>
  
  <p>The interesting thing there is that the php binary is identical to php7.1 but when called as the specific it doesn't show the already loaded message.</p>
  
  <hr>
  
  <p>Edit, 20181006:</p>
  
  <p>I still have this issue. The image below is a diff of the output of the two <code>php --ini</code> calls. As you can see, the sets of ini files loaded are the same.</p>
  
  <p><a href="https://i.stack.imgur.com/P8aVT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/P8aVT.png" alt="enter image description here"></a></p>
  
  <p>They are also the same symlinked binaries:</p>
  
  <pre><code>ben@ben-work:~$ which php
  /usr/bin/php
  ben@ben-work:~$ ls -la /usr/bin/php
  lrwxrwxrwx 1 root root 21 May 15 16:07 /usr/bin/php -&gt; /etc/alternatives/php
  ben@ben-work:~$ ls -la /etc/alternatives/php
  lrwxrwxrwx 1 root root 15 May 30 10:13 /etc/alternatives/php -&gt; /usr/bin/php7.1
  ben@ben-work:~$ which php7.1 
  /usr/bin/php7.1
  </code></pre>