🌙
Happy Karwa Chauth! Wishing all couples a blessed Karwa Chauth. May your bond grow stronger every year. From Team Job...
💬 Share
Web Development Tutorials

Debugging PHP Errors: White Screens, 500 Errors and Common Warnings Fixed

A blank page or "500 Internal Server Error" tells you nothing. Here's how to find and fix PHP errors quickly, locally and on live hosting.

In this article · 6 sections
  1. Step 1: See the error
  2. Common errors and fixes
  3. 500 Internal Server Error
  4. Debugging techniques
  5. Prevent errors
  6. FAQs
  7. Is it safe to show errors on a live site?
  8. Where do I find the error log on Hostinger?

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:

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

Share this article

Joboo Web

Web design, SEO & digital marketing team · Ludhiana, Punjab

Joboo Web has helped Indian businesses grow online since 2019 — building fast websites and running SEO, Google Ads and social campaigns for clients in 80+ cities. About us →

Keep reading

💬