Debugging PHP by monitoring errors in terminal

This is a super simple command but there is something about the following sequence of characters that I simply cannot retain in my brain.

tail -f /tmp/php-errors

This is a handy command to debug your PHP on your server where you may have errors hidden.

  • The tail command shows the end of a file.
  • The -f flag tells it to keep the file open, while you debug your code
  • The /tmp/php-error is ( I assume! ) a temporary error log file that stores PHP errors on the server.
  • .

Update:

If you use error_log(print_r(debug_backtrace(), true )) with this command, you can monitor the call stack in real time. Super useful when debugging!

5 thoughts on “Debugging PHP by monitoring errors in terminal

  1. This doesn’t even work… why would you post it? php doesn’t keep a file at tmp/php-errors. it would be useful to post where the actual php error log file lives.

    1. @eric, does it matter where the log file resides? The content of the log file is echo’d to your terminal in realtime, that is why the command is useful for debugging.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s