【发布时间】:2015-09-14 04:26:12
【问题描述】:
我通过以下代码创建了一个文件
$dir = '/home/srikanth/Desktop';
if ( !file_exists($dir) ) {
mkdir ($dir, 0777);
}
//$code contains the code C code which i want to execute
file_put_contents ($dir.'/test.c', $code);
$path = "/home/srikanth/Desktop/test.c";
$Command = "gcc $path 2&>1";
exec($Command,$return_val,$error);
当我打开我的错误日志文件时 我看到以下错误
sh: 1: cannot create 1: Permission denied
gcc: error: 2: No such file or directory
我尝试了以下命令来更改权限,我目前使用的是 Ubuntu 14.04.2 和 Apache 服务器
chmod 0777 /home/srikanth/Desktop/test.c
sudo chmod -R 777 /home/srikanth/Desktop/test.c
sudo usermod -aG www-data root
addgroup www-data
我使用这些命令将 www-data 添加到根组 但我仍然继续在我的错误日志中获取相同的文件
【问题讨论】:
-
来自
cannot create .. Permission denied,错误很可能是因为 php/apache 用户无权在该目录中创建文件,这意味着gcc的输出。使用su "phpuser"; touch php-file.txt验证这一点,对于 apache 也是如此 -
将test.c文件放到你的项目中,运行一次php文件,因为有时它无法访问其他文件,而不是www文件夹
-
感谢@Tamil Selvan,但我得到“无法创建 /var/www/html/test.c”/var/www/html 是我放置 php 文件的目录,而且当我尝试更改路径 /var/www/html 的权限我得到“chmod:更改'/var'的权限:不允许操作”
-
我已经为我的文件提供了@AlexAndrei 上面提到的权限
标签: php ubuntu permissions exec