How do I use Linux commands in PHP?

It will be a short article, because there is nothing much to tell. I'll probably talk about the commands on the windows servers sometime next time. Today about linux.

The shell_exec feature will be used, accepting one option with a string in which the server command is located.
By the way, the team does not work in a safe mode.

Thanks to this command, you can write your own mini-computer or server control panel.
With shells you need to be extremely careful because they are quite a common reason for hacking your websites.

Shell is usually performed on behalf of www-data. To find out exactly, you need to execute such a shell-script:

$user_shell = shell_exec('whoami');
echo $user_shell;

You can also create bash scripts

shell_exec('sh script.sh');

For example, I've got a script that uses linux commands and shell_exec will bring information about the server's processor, lake, and video maps directly to your web page.

<?php
    echo "<pre>"; //open tag pre
 
    echo "Processor \n"; //We display the inscription "Processor", under which there will be info about the processor
    $cpu = shell_exec('cat /proc/cpuinfo | grep "model name"'); //use shell
    //thanks to the shell above we got processor information
    echo $cpu ."\n\n"; //Display processor info
 
    echo "RAM \n"; //We display an inscription under which there will be info
    $memtotal = shell_exec('cat /proc/meminfo | grep  "MemTotal:" | awk \'{print($2)}\''); //Get the bytes
    echo ($memtotal / 1024) . " мб \n\n"; //We translate the volume of RAM into megabytes
 
    echo "video card \n"; //We display the inscription about the video card
    $video = shell_exec('lspci | grep -E "VGA|3D"'); //We get a video card. Or video cards, if there are several
    echo $video; //We display on the screen
 
    echo "</pre>"; //close tag pre
?>