What are best practices for handling permissions when using PHP to run commands on a server?

When running commands on a server using PHP, it is important to handle permissions properly to ensure security and prevent unauthorized access. One best practice is to use the `sudo` command in combination with `escapeshellarg()` to properly escape and sanitize user input before executing commands. This helps prevent command injection attacks and ensures that only authorized users can run commands with elevated privileges.

<?php
$command = 'sudo ' . escapeshellarg('your_command_here');
$output = shell_exec($command);
echo $output;
?>