Xdebug on Ubuntu 16.04 with PHP7

After upgrading to Ubuntu 16.04, it didn't take me long to realise that PHP7 wasn't using any of the customisations I had in place for PHP5.6.

Since the location of php.ini has changed from /etc/php5/apache2/php.ini to /etc/php/7.0/apache2/php.ini, it was pretty straightforward to port my changes, but how was I supposed to get my extensions like xdebug back? The internet wasn't very helpful, until, in frustration, I stumbled on a simple apt-get command:

sudo apt-get install php-xdebug

You should check your PHP modules list and see xdebug in there now. You will also need to restart Apache2 if you are using it.

php -m
sudo service apache2 restart

But, there was a problem, I wasn't getting any stack traces. Adding a call to phpinfo() in my site showed that indeed, stack traces were turned off. So I edited the config file to manually enable traces on errors (just add the snippet to the bottom of the file).

vi /etc/php/7.0/mods-available/xdebug.ini
xdebug.show_error_trace = 1

After restarting Apache2 once again, everything was back to normal. In my case I also needed SOAP and CURL for a specific site, so I picked those up too with:

sudo apt-get install php-soap php-curl

Soap requires you to uncomment a line in your php.ini to work and as always, don't forget to restart Apache2.

 

UPDATE: It has come to my attention that xdebug exception traces trigger even if the exceptions are caught, this is not the kind of thing you normally want to see, so I have removed references to its use.

Replies to Post

The title of this post is "Xdebug on Ubuntu 16.04 with PHP7" but the post is not explaning how to get xdebug installed for php7 in Ubuntu 16.04.

It is just explaining how to upgrade from PHP5.6 to PHP7 and get xdebug working.

Thumbs up to apt-getting xdebug for php7 on 16.04!