How can one troubleshoot and debug PHP scripts that are not running as expected on a local server?

To troubleshoot and debug PHP scripts that are not running as expected on a local server, you can start by checking for syntax errors, ensuring that all required files are included correctly, and using var_dump() or echo statements to output variable values at different stages of the script. Additionally, enabling error reporting and logging can help identify any runtime errors or warnings that may be occurring.

<?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Check for syntax errors
if (count($errors = error_get_last()) > 0) {
    var_dump($errors);
}

// Include required files
require_once 'config.php';

// Output variable values
$variable = 'value';
var_dump($variable);
echo $variable;
?>