In this article · 6 sections
A white screen or a generic 500 error is frustrating because the real message is hidden. Debugging PHP errors is mostly about getting PHP to tell you what went wrong, then recognising the common patterns.
Step 1: See the error
On localhost (development), show everything at the top of your script or in php.ini:
<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
On a live site, don't display errors to visitors. Log them instead:
<?php
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', __DIR__ . '/../php-error.log');
Hosting panels (hPanel, cPanel) also have an Error Logs section.
Common errors and fixes
| Message | Meaning | Fix |
|---|---|---|
Parse error: syntax error, unexpected … |
Typo: missing ;, bracket or quote |
Check the line mentioned and the one before it |
Warning: Undefined array key "name" |
Reading $_POST['name'] when it isn't set |
Use $_POST['name'] ?? '' |
Warning: Undefined variable $x |
Using a variable before setting it | Initialise it first |
Cannot modify header information - headers already sent |
Output (even a space or BOM) before header() or session_start() |
Remove whitespace before <?php, save files as UTF-8 without BOM, call header() before any HTML |
Fatal error: Uncaught Error: Call to undefined function mysqli_connect() |
Extension not enabled | Enable mysqli in PHP settings |
Access denied for user / Connection refused |
Wrong DB credentials or host | Check name, user, password, host (localhost on most shared hosts) |
Allowed memory size exhausted |
Script using too much memory | Fix loops/large queries; raise memory_limit only if justified |
Maximum execution time exceeded |
Script running too long | Optimise, paginate, or move to a cron job. See cron jobs |
| Deprecated warnings after upgrading PHP | Old code patterns | Update code for PHP 8.x |
500 Internal Server Error
Often not PHP at all:
- A bad rule in
.htaccess. See .htaccess basics - Wrong file permissions (folders 755, files 644 on most shared hosts)
- PHP version mismatch after moving hosts. See deploying to Hostinger
Debugging techniques
var_dump($variable); exit;to inspect values at a point- Log with
error_log('Booking data: ' . print_r($data, true)); - Check the browser Network tab for the real status code. See DevTools guide
- Use Xdebug with VS Code for step-by-step debugging. See VS Code extensions
- Comment out half the code to find which part breaks (binary search)
Prevent errors
- Develop locally first. See XAMPP localhost
- Use Git so you can roll back. See Git basics
- Validate inputs and handle database failures gracefully
FAQs
Is it safe to show errors on a live site?
No. Error messages can reveal file paths and database details to attackers.
Where do I find the error log on Hostinger?
Check hPanel's error logs or the log file you configure in error_log.
Was this article helpful?
Your answer helps us improve our guides