为什么在使用 exec 命令时权限被拒绝(写入日志文件时)


Why Permission denied while using exec command(while writing to the log file )?

在我的本地机器中,我使用了exec命令,如下所示:

 if($serverHost == "api.frapi") 
 {
     $phpBianryPath='/Applications/MAMP/bin/php/php5.4.10/bin/php';
 }
 else
 {
     $phpBianryPath='/usr/bin/php';
 }
 $logDir= dirname(__FILE__). '/BackgroundTask';                
 exec("$phpBianryPath $logDir/notificationCall.php $token >> $logDir/log_file.log 2>&1 &");

它在我的本地机器中完美运行。但是当我将其上传到生产服务器上然后尝试使用它时,它会出现如下错误:

sh: /var/www/html/example/src/frapi/custom/Action/BackgroundTask/log_file.log:
Permission denied

请指导我。我不明白为什么它在生产中不起作用?

您没有执行该文件所需的权限。如果您正在运行脚本的服务器具有 linux,请使用 chmod 命令更改文件权限。

chmod 0764 /var/www/html/example/src/frapi/custom/Action/BackgroundTask/log_file.log

4 = 读取;

2 = 写入;

1 = 执行;

读+写+执行 = 4+2+1 = 7;

764 表示 RWX 表示所有者,rx 表示组,R 表示其他人。

有关更多文档,请参阅:https://help.ubuntu.com/community/FilePermissions