Debugging: Difference between revisions

From Freephile Wiki
remove spaces
No edit summary
Line 10: Line 10:
Ensure that XDebug extension is installed for your PHP environment.
Ensure that XDebug extension is installed for your PHP environment.


in the console, you can <code>php -r 'phpinfo();' | grep -i xdebug</code>
in the console, you can just type <code>php -v</code> which will tell you not just the version of PHP, but also whether XDebug is enabled. More specifically, you could <code>php -r 'echo phpversion("xdebug");'</code>


Or, better yet, create a file like '''info.php''' <syntaxhighlight lang="bash">
You should '''also''' check the settings of your installation by looking at the <code>ini</code> file for XDebug<br>
<code>php --ini</code> shows you the ini files that are loaded for your PHP. Inspect the one related to XDebug and ensure that it is set for Debugging.
 
<code>cat /etc/php/8.3/cli/conf.d/99-xdebug.ini</code>
<syntaxhighlight lang="bash">
zend_extension=xdebug
xdebug.mode=coverage,develop,debug,profile,trace
</syntaxhighlight>
 
Beware that although the '''mode''' is critical and can only be set in the ini file, that setting can be overridden by the environment variable '''XDEBUG_MODE''' - so look for that in container-driven setups.
 
=== Configuration Report ===
Create a file like '''info.php''' on your development host, and then browse it for a full report of your Debugging environment.
<syntaxhighlight lang="bash">
# choose a target
# choose a target
myFile='../../info.php';
myFile='../../info.php';
Line 19: Line 32:
# add the xdeub_info() function
# add the xdeub_info() function
echo -e "\n\nxdebug_info();\n" >> $myFile;
echo -e "\n\nxdebug_info();\n" >> $myFile;
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:03, 12 February 2025

Debugging a PHP application can involve quite a bit of machinery, and effort getting that machinery setup. But it's worth it because what alternative is there? echo? Come on!

Thanks to Derick Rethans, XDebug can do a ton of cool things for you. For example, it overloads var_dump() and gives you control over how you want deeply nested data structures to be displayed.

We did an old deep dive using NetBeans and XDebug on a complex CiviCRM mailer embedded as a module in Drupal

A more current setup would be debugging Semantic MediaWiki in a Docker container using VSCode with PHPDebug.

Install[edit]

Ensure that XDebug extension is installed for your PHP environment.

in the console, you can just type php -v which will tell you not just the version of PHP, but also whether XDebug is enabled. More specifically, you could php -r 'echo phpversion("xdebug");'

You should also check the settings of your installation by looking at the ini file for XDebug
php --ini shows you the ini files that are loaded for your PHP. Inspect the one related to XDebug and ensure that it is set for Debugging.

cat /etc/php/8.3/cli/conf.d/99-xdebug.ini

zend_extension=xdebug
xdebug.mode=coverage,develop,debug,profile,trace

Beware that although the mode is critical and can only be set in the ini file, that setting can be overridden by the environment variable XDEBUG_MODE - so look for that in container-driven setups.

Configuration Report[edit]

Create a file like info.php on your development host, and then browse it for a full report of your Debugging environment.

# choose a target
myFile='../../info.php';
# add the phpinfo() function
echo -e "<?php \nphpinfo();\n" > $myFile;
# add the xdeub_info() function
echo -e "\n\nxdebug_info();\n" >> $myFile;