How to display PHP errors?
P粉807397973
2023-08-23 10:45:28
<p>I have checked my PHP ini file (<code>php.ini</code>) and set <code>display_errors</code> and the errors are reported as <code>E_ALL</code> ;. I have restarted my Apache web server. </p>
<p>I even put these lines at the top of the script and it doesn't even catch simple parsing errors. For example, I declare a variable using <code>"$"</code> but do not close the statement <code>";"</code>. But all my scripts are showing a blank page on these errors, but I want to actually see the <strong>errors</strong> in the browser output. </p>
<pre class="brush:php;toolbar:false;">error_reporting(E_ALL);
ini_set('display_errors', 1);</pre>
<p>What else needs to be done? </p>
You can't catch parse errors in the same file with error output enabled at runtime, because it parses the file before actually executing anything (and since it encounters errors in the meantime, it doesn't execute anything). You need to change the actual server configuration so that display_errors is turned on and the appropriate error_reporting level is used. If you don't have access to php.ini, you might be able to use a .htaccess or similar file, depending on the server.
This question may provide more information.
Development environment
This always works for me:
However, this will not make PHP show parsing errors that occur in the same file - the only way to show these errors is to modify php.ini with the following line:
(If you don't have access to
php.ini
, putting this line in.htaccess
may also work):Product Environment
Please note that the above suggestions only apply to development environments. On the actual website it must be
Then you will be able to see all errors in the error log. SeeWhere to find the PHP error log
AJAX call
If it is an AJAX call, open DevTools (F12) on the development server and open the Network tab. Then make a request for the results you want to see and it will appear in the Network tab. Click it and then click the Response tab. There you will see the exact output.
While on the live server, just check the error logs.