Laravel (PHP) 500 Error: A step-by-step guide to fix it.

HTTP status code 500 means there’s something wrong with the server. It could be an error in your PHP app, an error in the webserver config file, or a module that is missing from your server.

Causes of 500 error

  1. Something is wrong in the PHP code: Sometimes the code has some sort of error eg: you might have a syntax error, a runtime error, etc. In order to check what’s wrong with your Laravel (PHP) app, you need to add the following lines in the PHP script from which the execution starts.
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);

For Laravel, you need to add the above three lines in public/index.php, for WordPress, it is index.php and for a core PHP website, it will be the name of the PHP script mentioned at end of the URL.

After adding the above three lines. Reload the page and you will see an error message. Search for that error message and you will surely get a solution for it. If you don’t see an error message then follow the next step.

2. Something is wrong with Web Server configuration: If you don’t get any error message in the browser after adding the above code. Then the issue is not the web app itself. It could be the webserver you are using the services of the app. So check the access logs and error logs of that webserver. For Apache its at /var/log/apache2/ or at `/var/log/httpd/`. For Nginx its at /var/log/nginx/.

In these files search for the path (part of the URL after domain) at which you are getting an error. Look at the last entry for that path in the file and search on Google for the error mentioned in that line.

Leave a Reply

Your email address will not be published.