Skip to content

Instantly share code, notes, and snippets.

@savyounts
Created March 7, 2019 19:52
Show Gist options
  • Save savyounts/2717ed59cfbeff9614a7dba975a88a8e to your computer and use it in GitHub Desktop.
Save savyounts/2717ed59cfbeff9614a7dba975a88a8e to your computer and use it in GitHub Desktop.
PHP Error_logs
To help debugging wiht PHP you can run error_logs. This should be a one time set up where you can go into your php.ini file and make a few changes.
/usr/local/etc/php/php.ini
Once in there you should make 3 changes, turn log_errors on, turn display_erros off and set a file that error_log should log to.
log_errors = On
display_errors = On
error_log = /usr/local/var/log/php/php_errors.log
Make sure that all of these lines are uncommented (don't have a ; in front of them)
You can set the errors_log file to any file you'd like, but you will have to go in and make that file.
Next, restart php (apache) and you should be able to run your logs. To make it simipler, it's a good idea to create a bash alias for this.
In your terminal type open -e .bash_profile
Once in the file, type
alias phplog='tail -f /usr/local/var/log/php/php_errors.log'
This creates a new alias called phplog that shows a continual stream of everything added to your error log.
Now, if you want to create custom errors to help you debug your code you can use the error_log() function. You can type in a custom
error message or you can have it output the value of a variable.
error_log("Look at this error");
error_log($var)
If you want to output a variable that isn't just a string, you'll need to use this version, otherwise if your variable is
an array, it will just output "array"
error_log(var_export($var, true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment