Linux Ubuntu PHP 运行 mkdir() Permission Denied 的原因
2016-05-16 12:20
543 查看
I know this is an old thread, but it needs a better answer. You shouldn’t need to set the permissions to 777, that is a security problem as it gives read and write access to the world. It may be that your apache user does not have read/write permissions on the directory.
Here’s what you do in Ubuntu
Make sure all files are owned by the Apache group and user. In Ubuntu it is the www-data group and user
chown -R www-data:www-data /path/to/webserver/www
Next enabled all members of the www-data group to read and write files
chmod -R g+rw /path/to/webserver/www
The php mkdir() function should now work without returning errors
我知道这是一个古老的帖子了,但它需要一个更好的答案。你不应该将权限设置为777,这不安全, 因为它给所有访问者读和写的权限。出现问题的原因可能是,你的apache用户不具有读/写权限的目录。
下面是在Ubuntu下你应该怎么做:
确保所有文件属于Apache组和用户。Ubuntu里面,指的是www - data组和用户
接下来赋予www-data组的所有成员以读和写的权限。
现在mkdir()应该可以正常工作了。
来自:
http://stackoverflow.com/questions/5246114/php-mkdir-permission-denied-problem
追加:
在这之后,我们发现,平时用自己的账户的时候,www目录没有写权限,干什么都要sudo,怎么办?
把自己加入www-data组就可以,这是我的解决方法。
注意G一定大写,小写表示覆盖当前组
然后注销登录即可。
这样一来,我发现自己不再sudoer之列了,也就是不能使用sudo su了,问题很严重。
解决办法是:
重启进入高级,recovery,挂到root,然后
运行
然后在
User privillege specification 下面复制粘贴root开头的一行,把root改成自己的用户名就可以了,然后ctrl+x退出时选择y保存,这样我的问题就解决了。
Here’s what you do in Ubuntu
Make sure all files are owned by the Apache group and user. In Ubuntu it is the www-data group and user
chown -R www-data:www-data /path/to/webserver/www
Next enabled all members of the www-data group to read and write files
chmod -R g+rw /path/to/webserver/www
The php mkdir() function should now work without returning errors
我知道这是一个古老的帖子了,但它需要一个更好的答案。你不应该将权限设置为777,这不安全, 因为它给所有访问者读和写的权限。出现问题的原因可能是,你的apache用户不具有读/写权限的目录。
下面是在Ubuntu下你应该怎么做:
确保所有文件属于Apache组和用户。Ubuntu里面,指的是www - data组和用户
chown -R www-data:www-data /path/to/webserver/www
接下来赋予www-data组的所有成员以读和写的权限。
chmod -R g+rw /path/to/webserver/www
现在mkdir()应该可以正常工作了。
来自:
http://stackoverflow.com/questions/5246114/php-mkdir-permission-denied-problem
追加:
在这之后,我们发现,平时用自己的账户的时候,www目录没有写权限,干什么都要sudo,怎么办?
把自己加入www-data组就可以,这是我的解决方法。
注意G一定大写,小写表示覆盖当前组
sudo usermod -G www-data yourUsername
然后注销登录即可。
这样一来,我发现自己不再sudoer之列了,也就是不能使用sudo su了,问题很严重。
解决办法是:
重启进入高级,recovery,挂到root,然后
mount -o remount,rw /
运行
visudo,
然后在
User privillege specification 下面复制粘贴root开头的一行,把root改成自己的用户名就可以了,然后ctrl+x退出时选择y保存,这样我的问题就解决了。
相关文章推荐
- 一个关于if else容易迷惑的问题
- Ubuntu 默认壁纸历代记
- Ubuntu Remix Cinnamon 20.04 评测:Ubuntu 与 Cinnamon 的完美融合
- Linux socket 初步
- 关于Ubuntu 11.10启动提示waiting for the network configuration的问题
- 在 Ubuntu 桌面中使用文件和文件夹
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- PHP5.2.*防止Hash冲突拒绝服务攻击的Patch
- 深入理解PHP之匿名函数
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- ubuntu下chrome无法同步问题解决