M
M
ms23452015-12-21 17:59:36
PHP
ms2345, 2015-12-21 17:59:36

Server error 500 instead of error alerts - what to do about it?

Good time. If errors in php code caused warnings like:
Warning: PDO::query(): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.wrongtable' doesn't exist in /tmp/pdo_test.php on line 18
Now any error in the code results in a server error (500).
As a result, the question arose - how to return the standard error debugger so that a server error does not occur.
There are only a couple of lines in the .htaccess file:
AddDefaultCharset UTF-8
DirectoryIndex index.php

Thank you very much for your attention!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OnYourLips, 2015-12-21
@OnYourLips

Now any error in the code leads to a server error (500).
This is normal behavior. And what you want is terrible: it will make errors undiagnosable.
You should read about working with exceptions in PHP: php.net/manual/ru/language.exceptions.php
then you can catch them and instead of 500 issue either a beautiful error message or handle it.

W
wol_fi, 2015-12-21
@wol_fi

try adding to .htaccess

php_flag display_errors On
php_value error_log /path/to/error.log
php_value error_reporting “E_ALL & ~E_NOTICE”

UPD.
if the php logs are empty, see more apache logs

M
MetaDone, 2015-12-21
@MetaDone

you don't have a wrongtable table in the test database, that's why it crashes
Apparently they forgot to create it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question