您的位置:首页 > 运维架构 > Linux

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组和用户

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保存,这样我的问题就解决了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息