Skip to main content
GrN.dk

Main navigation

  • Articles
  • Cases
  • Contact
  • Your Digital Project Manager
  • About Greg Nowak
  • Services
  • Portfolio
  • Container
    • Excel Freelancer
    • Kubuntu - tips and tricks
    • Linux Apache MySQL and PHP
    • News
    • Image Gallery
User account menu
  • Log in

Breadcrumb

  1. Home

Debugging PHP: A Practical Workflow for Faster Fixes

By Greg Nowak. Last updated 2026-07-07.

Debugging PHP is not a personality test for developers. It is a visibility problem. When a checkout fails, a webhook disappears, or a legacy template throws a blank page, the costly part is usually not the fix itself. It is the time spent guessing what the application actually saw, which branch it took, and where the failure first became visible.

For business owners, operations leads, and agency teams, the aim should be simple: make defects easier to reproduce, easier to inspect, and safer to investigate without exposing internal details to customers. The tools are familiar: PHP error reporting, production logging, focused variable inspection, and Xdebug when the path through the code is too tangled for log lines alone.

Start by separating development from production

In a local or short-lived staging environment, full visibility is useful. Set error reporting explicitly so the team is not relying on whatever the server image, hosting panel, or old project defaults happen to provide.

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>

If the problem happens during bootstrap, autoloading, or parsing, code-level settings may run too late. Put the settings in php.ini, a PHP-FPM pool, an Apache or Nginx/PHP configuration layer, or the hosting control panel instead.

display_errors = On
display_startup_errors = On
log_errors = On
error_reporting = E_ALL

Use that pattern for development investigations, not live public traffic. On production systems, PHP errors should be logged, not shown to users. Error screens can expose file paths, configuration details, stack traces, and business logic. They also make a professional site feel abandoned.

display_errors = Off
display_startup_errors = Off
log_errors = On
error_log = /var/log/php/error.log
error_reporting = E_ALL

That one split is worth enforcing across teams. Developers get enough information to diagnose the failure, while customers and editors are protected from raw internals.

Use logs to answer one question at a time

Bad debugging logs are just noise in a different place. Good logs answer a specific question: did the webhook arrive, which order ID failed, which branch was selected, what status did the payment provider return?

<?php
error_log('[checkout] order=' . $orderId . ' state=' . $state);
error_log('[checkout] provider_status=' . $providerStatus);
?>

For a temporary investigation, error_log() can also append to a dedicated file. Add the newline yourself when using append mode, because PHP does not automatically add it for that message type.

<?php
error_log('API response: ' . json_encode($response) . PHP_EOL, 3, __DIR__ . '/php-debug.log');
?>

Keep these logs disciplined. Prefer IDs, states, timings, and decision points. Avoid access tokens, passwords, full customer records, session cookies, and payment data. If sensitive data is genuinely needed for a controlled investigation, decide who can access the output and when it will be removed.

Situation Best first move Why it helps
Blank page in development Enable E_ALL, displayed errors, and startup errors in configuration. Shows parse, bootstrap, and runtime issues before the team starts guessing.
Customer-facing failure Keep display off, log errors, and add narrow temporary breadcrumbs. Protects users while giving developers evidence from the live path.
Wrong data or unexpected type Inspect the variable shape with a deliberate dump or captured dump file. Confirms whether the bug is data, type, mapping, or business logic.
Complex branching or framework lifecycle Use Xdebug step debugging with trigger-based activation. Shows the actual execution path without turning every request into a debug session.
A practical PHP debugging decision matrix for choosing the least noisy tool first.

Inspect variables deliberately

var_dump() is still useful because it shows both type and value. That matters in PHP projects where a value may arrive as a string from a request, an integer from a database layer, a nullable object from an ORM, or a nested array from an API response.

<?php
var_dump($payload);
?>

The poor habit is leaving dumps scattered through templates or returning them to a browser on shared environments. When you need to compare output, capture it cleanly and put the file somewhere controlled.

<?php
ob_start();
var_dump($payload);
$dump = ob_get_clean();
file_put_contents(__DIR__ . '/dump.txt', $dump);
?>

If the dump may include credentials, customer data, or private paths, do not place it under a public web root. For agency work, make cleanup part of the ticket definition of done: temporary dumps removed, noisy logs removed, and any useful learning moved into a test, runbook, or monitoring rule.

Bring in Xdebug when logs are not enough

Logs are usually enough for straightforward bugs. Xdebug becomes valuable when the issue depends on several layers of state: middleware, framework events, hooks, dependency injection, legacy includes, or queue workers. In those cases, stepping through the code can be cheaper than trying to reconstruct the path from scattered output.

A sensible development default is to enable the debugger and development helpers, then start sessions only when requested:

xdebug.mode=debug,develop
xdebug.start_with_request=trigger

For command-line scripts, a triggered run keeps normal executions clean:

XDEBUG_TRIGGER=1 php your-script.php

Remember that xdebug.mode is a startup setting, so it belongs in php.ini or an Xdebug ini file read when PHP starts. If you use environment variables with PHP-FPM, check whether the server passes them through; some setups clear environment variables by default.

Make the fix improve the process

A good debugging workflow is repeatable: reproduce the issue, increase visibility in the right environment, add one or two high-signal observations, inspect the actual data, step through with Xdebug when needed, then clean up. The final step is where teams mature. Convert the lesson into a test, validation rule, alert, checklist, or deployment note so the same class of issue is easier next time.

If your PHP project is losing time to unclear handoffs, fragile releases, or production-only failures, Greg can help tighten the debugging workflow and the operational process around it.

Related on GrN.dk

  • AI Crawler Control for Business Websites: Protect Content Without Sacrificing Search Visibility
  • PHP Test If Front Page: Safer Homepage Detection in Plain PHP
  • AI automations need a spend dashboard before the first runaway bill

Need help with this kind of work?

Improve your PHP delivery workflow Get in touch with Greg.

Sources

  • PHP: error_reporting - Manual
  • PHP: Runtime Configuration - Manual
  • PHP: error_log - Manual
  • PHP: var_dump - Manual
  • Xdebug: Step Debugging
Last modified
2026-07-07

Tags

  • php
  • Debugging
  • Xdebug
  • Error Logging
  • Web Operations
  • Log in to post comments

Review Greg on Google

Greg Nowak Google Reviews

 

Illustrated infographic summarizing: One Timeout, Two Orders: Make AI Actions Safe to Retry
One Timeout, Two Orders: Make AI Actions Safe to Retry
2026-07-25

A timed-out AI action may already have succeeded. Stable keys, durable ledgers, queues and stored results prevent a routine retry from duplicating real work.

Illustrated infographic summarizing: Your AI Visibility Dashboard Needs a Methodology, Not More Charts
Your AI Visibility Dashboard Needs a Methodology, Not More Charts
2026-07-24

A practical framework for measuring AI-search visibility with fixed prompts, repeated tests, separate metrics, retained evidence, and honest reporting.

Illustrated infographic summarizing: AI Admin APIs Are Here—But Your Directory Is Still the Source of Truth
AI Admin APIs Are Here—But Your Directory Is Still the Source of Truth
2026-07-23

New AI admin APIs can automate access and spend controls, but reliable governance still starts with authoritative directory data and clear ownership.

Illustrated infographic summarizing: OpenAI Presence Arrived—But Is Your Workflow Ready for an Agent?
OpenAI Presence Arrived—But Is Your Workflow Ready for an Agent?
2026-07-22

Before an AI agent can take on real work, its workflow needs clear scope, permissions, handoffs, evaluation cases, and production monitoring.

Illustrated infographic summarizing: Chatbot Transcripts Quietly Became a Retention and Redaction Problem
Chatbot Transcripts Quietly Became a Retention and Redaction Problem
2026-07-21

Chatbot transcripts spread across providers, logs and support tools. Here is how to map each copy, redact sensitive data and test deletion properly.

Illustrated infographic summarizing: Cloudflare Service Keys Stop in September: Find Every Caller
Cloudflare Service Keys Stop in September: Find Every Caller
2026-07-20

Cloudflare Service Keys stop working on September 30, 2026. Here is how to find every caller, move to scoped API tokens and avoid a late outage.

Illustrated infographic summarizing: Your AI Workflow Needs an Acceptance Test Before It Meets Customers
Your AI Workflow Needs an Acceptance Test Before It Meets Customers
2026-07-19

A practical way to test AI workflows using realistic scenarios, tool checks, human rubrics, regression suites, and clear release gates.

Three cover candidates for The Goats Were Load-Bearing fanned on a dark background: an ember-lit door, three slow knocks, and a founders' ledger
The Goats Were Load-Bearing: a fantasy where the bill always comes due
2026-07-19

A teaser for the upcoming darkly comic fantasy novel The Goats Were Load-Bearing — a village, a door that must stay poor, and the worst possible time to sell the herd. Readers pick the cover.

Vegan Power game: the yellow player catches falling fruit while a chicken and a cow look on
Vegan Power: The Little Game About Eating Fruit, Not Friends
2026-07-19

Vegan Power is a free browser game where you catch fruit, dodge the animals, protect seven hearts, and chase a better high score.

KotobaMon title screen: the Japanese logo コトバモン over a low-poly 3D island with monsters, cherry-blossom trees and a trainer.
KotobaMon: Shipping a 3D Browser Game With No Build Step and Self-Hosted Voice
2026-07-19

A look at fantasy.grn.dk, a browser-based 3D game that teaches Japanese with no build step, procedural art and self-hosted AI voice, and what its constraints show about shipping interactive products fast and cheap.

More articles
RSS feed

GrN.dk web platforms, web optimization, data analysis, data handling and logistics.