php - 无法使用 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
}
解决方案
推荐阅读
- python - Azure Speech-To-Text 多语音识别
- php - 'unoconv' 脚本在终端中有效,但在我的 laravel 控制器中通过 exec() 函数调用时无效
- python - 没有默认构造函数的对象成员的 Swig setter
- java - 回溯递归问题以解决平衡括号
- iframe - 如何使用 Cypress 处理正确 iframe 的加载?
- scala - -Xlint:unsound-match 标志在 Scala 中有什么作用?
- scala - 理解 Scala 对抽象类型和类的使用
- html - 如何仅使用 CSS 为可变数量的列创建选项卡式导航
- django - Wagtail - 如何在管理表单中预先填充字段?
- vue.js - 如何动态呈现不同数据表的列表