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

 

Illustrated infographic summarizing: OpenAI Is Retiring Agent Builder: Save the Workflow, Not Just Prompts
OpenAI Is Retiring Agent Builder: Save the Workflow, Not Just Prompts
2026-07-10

OpenAI retires Agent Builder on November 30, 2026. Here is what teams need to preserve, how to choose a migration path, and how to cut over safely.

Illustrated infographic summarizing: Google’s AI Search toggle needs a test plan, not a gut decision
Google’s AI Search toggle needs a test plan, not a gut decision
2026-07-11

Google’s AI Search control creates a measurable publishing choice. Test visibility, traffic and leads before changing the setting across your site.

Illustrated infographic summarizing: WordPress 7.0 Has an AI Client. Plugins Need Their Own Guardrails
WordPress 7.0 Has an AI Client. Plugins Need Their Own Guardrails
2026-07-12

WordPress 7.0 standardizes how plugins call AI providers, while leaving developers responsible for access control, cost limits, capability checks and graceful failures.

Illustrated infographic summarizing: Search Console Can See Social Posts—Your Reports Need a New Map
Search Console Can See Social Posts—Your Reports Need a New Map
2026-07-13

Search Console now reports how social posts perform across Google. Here’s a practical way to manage properties, permissions, baselines and exports.

Illustrated infographic summarizing: If the Facts Need JavaScript, AI Search May Miss the Full Page
If the Facts Need JavaScript, AI Search May Miss the Full Page
2026-07-14

A practical guide to finding and fixing JavaScript rendering gaps that can hide services, prices, contact details and metadata from AI search crawlers.

Hand-drawn sketch infographic summarizing: Drupal's June security bundle exposes fragile Composer update habits
Drupal's June security bundle exposes fragile Composer update habits
2026-06-22

Drupal's June 2026 security releases show why Composer updates need staging, dependency review, JSON:API checks, oEmbed settings, and a runbook.

Hand-drawn sketch infographic summarizing: Model Retirements Are Quietly Breaking AI Integrations
Model Retirements Are Quietly Breaking AI Integrations
2026-06-23

Hard-coded AI model IDs can fail when vendors retire models. A practical guide to finding, testing, and migrating integrations before shutdown dates arrive.

Hand-drawn sketch infographic summarizing: WordPress Speculative Loading Needs a Cart, Analytics, and Cache Test
WordPress Speculative Loading Needs a Cart, Analytics, and Cache Test
2026-06-24

WordPress 6.8 adds cautious speculative loading. Before enabling stronger prerendering, test cart state, analytics, personalization, and cache load.

Hand-drawn sketch infographic summarizing: ChatGPT Is Becoming Office Software: Put Admin Hygiene First
ChatGPT Is Becoming Office Software: Put Admin Hygiene First
2026-06-24

ChatGPT now has files, sessions, apps, and scheduled work. Treat it like office software: audit access, clean up retained data, and limit risk.

Hand-drawn sketch infographic summarizing: AI images need a media-library audit before they reach clients
AI images need a media-library audit before they reach clients
2026-06-24

AI-generated images can carry provenance signals, but CMS resizing, plugins, and CDNs may change them. Audit the media path before delivery.

More articles
RSS feed

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