How can PHP be used to execute Linux commands for retrieving server information?

To execute Linux commands for retrieving server information using PHP, you can use the `exec()` function. This function allows you to run shell commands from within a PHP script. By using `exec()`, you can retrieve server information such as CPU usage, memory usage, disk space, and more.

<?php
// Execute a Linux command to retrieve server information
$cpuInfo = exec('cat /proc/cpuinfo | grep "model name"');
$memoryInfo = exec('free -m | grep Mem');
$diskInfo = exec('df -h');

// Output the retrieved server information
echo "CPU Info: $cpuInfo <br>";
echo "Memory Info: $memoryInfo <br>";
echo "Disk Info: <pre>$diskInfo</pre>";
?>