Skip to main content
GrN.dk

Main navigation

  • Articles
  • 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

 

  • Support bots need a deletion test before they learn the old help center
  • AI shopping visibility now depends on boring product-data plumbing
  • OpenAI Evals Bring Acceptance Tests to AI Workflow Releases
  • Debugging PHP: A Practical Workflow for Faster Fixes
  • AI Shopping Makes Product Data Integrity a Technical Ops Job
RSS feed

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