Do you have APP_ENV=local and APP_DEBUG=true in your env file ?
Herd not displaying actual php error. it's showwing 500 error
II am currently working on a PHP project, and I've encountered an issue where my controller is producing an error. However, instead of displaying the actual error message, Herd is returning a 500 Internal Server Error.
@Snapey Yea Problem in nginx configuration. In apache server error are showing.
To diagnose and display the actual PHP error instead of a generic 500 Internal Server Error, you can follow these steps:
-
Enable Error Reporting in PHP: Ensure that PHP is configured to display errors. You can do this by modifying your
php.inifile or by adding the following lines at the beginning of your PHP script:ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); -
Check Your Web Server Configuration: Sometimes, the web server configuration might be suppressing the error messages. If you are using Apache, make sure that the
display_errorsdirective is set toOnin your.htaccessfile or in the server configuration:php_flag display_errors onFor Nginx with PHP-FPM, ensure that the
php.inifile used by PHP-FPM hasdisplay_errorsenabled. -
Review Your Error Logs: Check the web server error logs for more detailed information about the error. For Apache, the error log is usually located at
/var/log/apache2/error.log, and for Nginx, it is typically at/var/log/nginx/error.log. -
Use a Custom Error Handler: Implement a custom error handler in your PHP application to catch and display errors more gracefully. Here is an example of a simple custom error handler:
set_error_handler(function ($errno, $errstr, $errfile, $errline) { echo "<b>Error:</b> [$errno] $errstr - $errfile:$errline"; echo "<br>"; echo "Terminating PHP script."; die(); }); // Example code that triggers an error echo $undefined_variable; -
Check for Fatal Errors: If your script is encountering a fatal error, it might not be displayed due to the script termination. You can use the
register_shutdown_functionto catch fatal errors:register_shutdown_function(function () { $error = error_get_last(); if ($error !== NULL) { $info = "[SHUTDOWN] level: {$error['type']}, message: {$error['message']}, file: {$error['file']}, line: {$error['line']}"; echo $info; } }); // Example code that triggers a fatal error non_existent_function();
By following these steps, you should be able to see the actual PHP error messages instead of a generic 500 Internal Server Error. This will help you debug and resolve the issue more effectively.
I have the same issue, as if the team behind Herd made all errors disappear; could it be because I'm not a pro member of Herd?
Please or to participate in this conversation.