What are some best practices for troubleshooting PHP scripts that interact with server commands like "dnscmd"?

Issue: When interacting with server commands like "dnscmd" in PHP scripts, it is important to ensure that the necessary permissions are set for the PHP script to execute the command successfully. Additionally, it is crucial to handle any errors or exceptions that may occur during the execution of the command. PHP Code Snippet:

<?php

// Set the command to be executed
$command = 'dnscmd <server_name> /ZoneAdd <zone_name> /Primary /file <zone_file>';

// Execute the command and capture the output
$output = shell_exec($command);

// Check for any errors during command execution
if ($output === false) {
    echo "Error executing command";
} else {
    echo "Command executed successfully";
}

?>