How to execute Linux commands in PHP?
You can run Linux commands in PHP using the exec() function or the shell_exec() function.
- execute()
<?php
// 执行一个命令,并将结果保存到一个变量中
$result = exec('ls');
echo $result;
?>
- Execute shell commands in PHP.
<?php
// 执行一个命令,并将结果作为字符串返回
$result = shell_exec('ls');
echo $result;
?>
Please make sure that the server has sufficient permissions before executing the command.