PHP

Force showing errors

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
for ($i=0;$i<10;$i++) {
  restore_error_handler();
  restore_exception_handler();
}

Execute shell command

If available use Symfony Process

<?php

$command = 'ls';

$namedpipes = [
    1 => 'STDOUT',
    2 => 'STDERR'
];
$boundary ="--\n";
$descriptorspec = array(
    0 => array("pipe", "r"), // STDIN
    1 => array("pipe", "w"), // STDOUT
    2 => array("pipe", "w")  // STDERR
);
header("Content-Type: text/plain;charset=utf8");
echo "{$boundary}Executing: $command\n\n";
$process = proc_open($command, $descriptorspec, $pipes, $cwd = '/', $env = []);
stream_set_blocking($pipes[2], 0);

foreach ($namedpipes as $index => $pipe) {
    $buffer = stream_get_contents($pipes[$index]);
    echo $boundary . $namedpipes[$index] . ":\n";
    echo $buffer;
    fclose($pipes[$index]);
}

$return_value = proc_close($process);

echo ("{$boundary}EXIT CODE: ".var_export($return_value, true)."\n");

echo "{$boundary}DONE.\n";