首页 > 解决方案 > 无法使用 PHP 脚本执行 Shell 命令

问题描述

目前我正在研究一个可以在 linux 根服务器上执行 shell 命令的 PHP 脚本。

我想授予任何具有正确密码 (htacces) 的用户执行此脚本的权限(用于创建 OpenVPN 客户端)。当我跳转到 plesk 界面在文件数据管理器中执行 PHP 脚本时,我收到内部服务器错误 500。出于测试目的,我已经将 PHP 脚本的权限更改为 777。

我还控制了 php.ini 来检查 shell_exec/proc_open/exec 是否在被禁止的函数列表中。

如何将服务器/php 脚本配置为对脚本具有 root 权限?

使用 php 脚本执行 shell 命令时,是否可以使用 root 权限登录?

提前致谢。

祝你今天过得愉快。

编辑:当前代码是:

shell_exec('cd ' . $path-openvpn-ca);
shell_exec('source ./vars');


$descriptorspec = array(
    0 => array("pipe", "r"),  // stdin read by child
    1 => array("pipe", "w"),  // stdout written to by child
    2 => array("file", "error.log", "a") // stderr
);
$process = proc_open($path_openvpn-ca. "/build-key.sh LC_1234", $descriptorspec, $pipes);
if (is_resource($process)) {
    fwrite($pipes[0], PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. PHP_EOL. "." . PHP_EOL. "." PHP_EOL. "y" . PHP_EOL. "y". PHP_EOL);
    fclose($pipes[0]);
    $output = $pipes[1]; // $pipes[0] is the input and $pipes[2] is the error output
}

标签: phpshellroot

解决方案


推荐阅读