php - 使用 PHP 运行 Debian Bash 脚本

标签 php linux bash shell debian

我在使用 PHP 运行 bash 文件时遇到问题。

PHP 文件:

chdir('/var/www/PATH/inc/bash/');
exec('./status.sh argument, $output);

Bash 文件:

#!/bin/bash
echo 'test' >> /var/www/PATH/inc/bashOutput/test.txt

PHP 文件(ls -al handler.func.php):

-rw-r--r-- 1 root root 461 Jul  5 11:35 handler.func.php

Bash 文件(ls -al status.sh):

-rwxr-xr-x 1 root root 255 Jul  5 11:39 status.sh

脚本通过 root 和 SSH 运行。

我不是 Linux 专家。 但我认为这是文件所有者的问题。

但我过去已经用“chown”造成了一些损害,所以如果问题确实存在,我希望更有经验的人提供一些指导。

谢谢你的帮助, 康诺尔。

最佳答案

Script is working using through root with SSH.有问题。当 PHP 脚本通过 Web 请求运行时,它通常作为用户 www-data 运行。无论如何<?php exec('./status.sh argument, $output);?>在安全漏洞中。大多数服务器管理员会禁用此功能。

您的另一个选择是输入 sudo在你的 exec 函数中 exec('sudo bash /var/www/PATH/inc/bash/status.sh') .随着使用绝对路径运行脚本 bash /var/www/PATH/inc/bash/status.sh

为什么不能在脚本上运行 cron?

关于php - 使用 PHP 运行 Debian Bash 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44925800/

相关文章:

Bash:有 CTRL-C 时如何中断此脚本?

php - 在 PHP 中根据其他值循环遍历值

PHPExcel为每个结果添加多个工作表 PHP mysql

c++ - 如何在 Linux 下安装 Haskell? - 官方文档中的错误?

c - 在 Linux 中开发 C 应用程序时重要且方便的工具和命令

string - 找到模式并将其移至行尾

php - 在PHP中获取意外的文件结束错误

php - Paypal IPN 取消成员(member)资格 PHP

linux - 如何编辑脚本,使变量值包含在撇号内而不需要用户添加撇号?

bash - -bash : command substitution: line XX: syntax error: unexpected end of file