duanlinma5885 2014-06-09 20:33
浏览 40

PHP shell_exec似乎失败了

I'm trying to write a script for a client to reset the mysql service whenever they need to. (they're using a janky CMS/eccomerce that sometimes messes with the database in weird ways and it needs to be reset)

This issue is that shell_exec doesn't seem to be working, the var_dump statement outputs NULL and the mysql server is not reset.

The snippet of code that does the resetting looks like this

$output =  shell_exec('/usr/bin/sudo /bin/restartmysql');
var_dump($output);

/bin/restartmysql is a binary wrapper for restarting the database, the source for it looks like this

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int main(char argc, char** argv) {
  setuid(0);
  system("/usr/sbin/service mysql restart");
  return 1;
}

I've doubled checked and shell_exec is not disabled in my php.ini, also www-data has correct permissions to execute restartmysql

here's the sudoers snippet

www-data       LOCAL=NOPASSWD:/bin/restartmysql

Update:

When redirecting to stderr it showed that it was attempting to ask for a password with sudo, which was actually not needed because of the way the permissions are on the binary wrapper. However when removing sudo from the command I still receive this error.

string(106) "/usr/sbin/service: 127: /usr/sbin/service: stop: not found
/usr/sbin/service: 128: exec: start: not found
"
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog