Debugging PHP applications on UbuntuPosted on: 2022-04-19 15:57:13
I'm cleaning out some notes and wanted to put this somewhere...
- Crashes go to /var/crash.
- Make sure ulimit -c unlimited is run. Restart php-fpm.
Or see: https://bugs.php.net/bugs-generating-backtrace.php
In order to “unpack them” you use
apport-unpack <crash> ~/destination.
Then, you can use
gdb cat ExecutablePath
CoreDump within that directory to examine it.
You’ll need the debug symbols loaded for php-fpm. If you’re using the one from sury: https://github.com/oerdnj/deb.sury.org/issues/512
Basically, add the main/debug repos and then apt-get install the correct php7.4-fpm-dbgsym (or 8.0, whatever, you do you)
You also probably want the dbg helpers for zend: https://reverseengineering.stackexchange.com/questions/9558/how-to-get-current-php-function-name-in-gdb https://derickrethans.nl/what-is-php-doing.html
Get the current version of .gdbinit: https://github.com/php/php-src/blob/master/.gdbinit
Then you can review the stacktraces...