What are some PHP functions that can be used to execute shell commands on a server?

When working with PHP, you may need to execute shell commands on the server for various reasons such as running system commands or interacting with external programs. PHP provides several functions that can be used to execute shell commands, such as exec(), shell_exec(), passthru(), system(), and proc_open(). These functions allow you to run shell commands and capture their output or return status.

// Using exec() function to execute a shell command
$output = [];
$return_var = 0;
exec('ls -la', $output, $return_var);
if ($return_var === 0) {
    foreach ($output as $line) {
        echo $line . PHP_EOL;
    }
} else {
    echo 'Error executing command';
}