Install XDebug
Updated on 02 Feb 2020
check if xdebug is already installed
xdebug is a PHP extension. When running php -m
you should see it showing up under [Zend Modules]. If it is not there you will need to install it.
Installing & phpize not found
Installing xdebug can be done with the following command.
sudo pecl install xdebug
However, you may encounter an error message sh: 1: phpize: not found
.
phpize is installed as part of the dev packages of PHP. First find out which version of PHP you are running with php -v
.
Then install the PHP dev packages with the following command.
sudo apt-get install php7.2-dev
If it all goes well you’ll get plenty of feedback as shown below.
Install xdebug
Next step is to actually install xdebug. With the php-dev packages installed (with phpize), you can install with the following command.
sudo pecl install xdebug
Configure Options - Version 2
In the /etc/php/7.2/mods-available directory, a new entry has been added from the install process. xdebug.ini. We want to make the following modifications to the file.
zend_extension=xdebug.so
xdebug.remote_autostart=on
xdebug.remote_enable=1
xdebug.remote_log=/var/log/apache2/xdebug.log
Note: You may need to provide write access to the log file.
Configure Options - Version 3
Version 3 of xdebug has a different set of configuration options. In fact a lot of the settings now have different names, and you can read more about that in the xdebug upgrade page.
This is the minimun that is needed to have xdebug version 3 running.
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.start_with_request=yes
Build XDebug from PHP source
If you are building PHP from source, then you will need to:
- download the xdebug source and build it.
- enable debug during the
configure
stage of PHP.
Goto xdebug, download the source and untar.
wget https://xdebug.org/files/xdebug-2.7.2.tgz -O xdebug-2.7.2.tgz
tar -xzf xdebug-2.7.2.tgz
Build xdebug.
cd xdebug-2.7.2/
phpize
./configure --enable-xdebug
make -j number_of_cores_or_processors_CPU_has
sudo make install
Build PHP making sure that you -enable-debug
./configure \
--enable-debug
Tell PHP to use XDebug. This is the same as the earlier section Configuration - ini file You may need to physically hard-code the path to the xdebug.so
file. Also note that the extension type that is loaded is zend_extension
.
[xdebug]
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=on
xdebug.remote_log=/var/log/apache2/xdebug.log
Sanity Checks
To see where the PHP config files and extensions are loaded, run the following command.
php --ini
To the modules that are loaded.
php -m
Next Step
The next step is to configure your IDE (I use VS Code) to use XDebug for your command line and web scripts.