sed -i无法在php shell_exec()中工作

时间:2012-06-18 21:35:48

标签: php apache bash sed shell-exec

我希望能够在php文件中使用shell_exec()远程删除/添加开发横幅。从php / apache运行时,sed -i函数不起作用。 SELINUX被禁用。从终端运行test.sh作为另一个用户工作得很好。浏览器返回以下内容:

    Reset/Set Environments

    Running now...
    /sbin/nologin
    sed is /bin/sed
    sed: couldn't open temporary file /var/www/html/folder/folder/folderwithoutwritepermission/sed63Klhk: Permission denied
    EOF

以下是代码:

PHP文件:

<!DOCTYPE HTML> 
<html> 
<head> 
    <title>Reset/Set Environments</title> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
</head> 
<body> 

<h1>Reset/Set Environments</h1>

<?php

$output = shell_exec('sh /var/www/html/pages/test.sh');
echo("<pre>{$output}</pre>");

?>

</body> 
</html>

test.sh:

#!/bin/bash

cd /var/www/html/pages/;

echo "Running now...";

echo $SHELL;

type -a sed;

find -L /var/www/html/ -name 'template.php' 2>&1 | xargs sed -i 's/<body>/<body><div style=\"position: fixed; padding: 14px; background-color: #00ff00; width:100%; opacity: 0.5;\"><span style=\"color: #009900; font-size: 14px; font-weight: bold;\">DEVELOPMENT ENVIRONMENT<\/span><\/div>/g' 2>&1

echo "EOF";

1 个答案:

答案 0 :(得分:0)

问题是用户帐户apache正在运行,并将其shell设置为/bin/nologin

请参阅http://www.cyberciti.biz/tips/howto-linux-shell-restricting-access.html