Enable debugging in PHP via Xdebug - rajivkanaujia/alphaworks GitHub Wiki
Enable debugging in PHP via Xdebug
The debugger will be used for debugging PHP code
Test PHP
$ php --version
PHP 7.3.11 (cli) (built: Jun 5 2020 23:50:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
Find the location of php.ini file in use
$ php -i | grep "php.ini"
Configuration File (php.ini) Path => /etc
Enable Debugging
Check if Xdebug already exists in the php extension directory / folder
$ ls /usr/lib/php/extensions/
no-debug-non-zts-20180731
If /usr/lib/php/extensions/no-debug-non-zts-20160303/
folder is present it means you don’t have to worry about anything just open your php.ini and make some changes.
Make changes to php.ini
Earlier step showed you how to find the location of php.ini by using command $ php -i | grep "php.ini"
$ ls -lh /etc/php*
-rw-r--r-- 1 root wheel 5.2K Jun 6 02:53 /etc/php-fpm.conf.default
-r--r--r-- 1 root wheel 70K Jun 6 02:55 /etc/php.ini.default
/etc/php-fpm.d:
total 16
-rw-r--r-- 1 root wheel 19K Jun 6 02:53 www.conf.default
Copy php.ini.default to php.ini
$ cd /etc
$ sudo cp php.ini.default php.ini
Edit php.ini
$ sudo nano php.ini
or use Visual Studio Code
$ open -a /Applications/Visual\ Studio\ Code.app/ php.ini
At the end of the “Dynamic Extensions” section of the php.ini file, add following
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
At the end of php.ini, add following
[xdebug]
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
Save the file. Check to ensure the values are there
$ cat php.ini | grep xdebug
zend_extension=/usr/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
[xdebug]
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9000
Test if the debugger is configured. Check for Xdebug
$ php --version
PHP 7.3.11 (cli) (built: Jun 5 2020 23:50:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.7.0, Copyright (c) 2002-2019, by Derick Rethans <-- See this
Note: If you like the instructions here, please refer it on your posts/documentation. Contact me if there are corrections needed.