PHP无法用mkdir目录 [英] PHP unable to create a directory with mkdir
问题描述
我有一个previously工作的PHP脚本,它能够创建一个目录的mkdir
:
$ webfolder =在/ var / www / html等/图片/用户;
的mkdir($ webfolder,0770);
我做了一些修改该文件夹的/ var / www / html等/图像
这是现在的权限设置:
drwxrwx ---。自己的Apache system_u:object_r:httpd_sys_content_t:S0图片
我觉得previously这个文件夹是由拥有阿帕奇
。但是,由于阿帕奇
已阅读的完全权限,写和执行作为用户组,我不知道为什么它不能创建中的文件夹。使用的mkdir
生成一个假
布尔值。
该问题是由于目录的所有权还是有其他原因?请注意,我使用的PHP版本5.4。
错误日志说:
[周一12月17日11时12分34秒2012] [错误] [客户端127.0.0.1] PHP的警告:
MKDIR():权限在/ var / www / html等/否认上传第33行,
引用者: https://mywebsite.com/referer
块引用>解决方案答案是正确的盯着我的面前,但是我想念它因我不熟悉SELinux的。
SELinux上下文类型应设置为
httpd_sys_content_rw_t
而不是httpd_sys_content_t
这样的文件夹是可读和可写的为Apache。改变的背景递归用下面的命令来完成:#chcon这个-r -t httpd_sys_content_rw_t的/ var / www / html等/图片
天哪。希望它可以帮助别人谁遇到这一点。
I have a previously working PHP script that is able to create a directory with
mkdir
:$webfolder = "/var/www/html/images/user"; mkdir($webfolder, 0770);
I made some changes to the permission setting of the folder
/var/www/html/images
which is now:drwxrwx---. myself apache system_u:object_r:httpd_sys_content_t:s0 images
I think previously this folder was owned by
apache
. But sinceapache
has the full privileges of read, write and execute as a user group, I wonder why it can't create a folder within. Using themkdir
produces afalse
boolean value.Is the problem due to directory ownership or is there some other reasons? Note that I am using PHP version 5.4.
Error Log added:
[Mon Dec 17 11:12:34 2012] [error] [client 127.0.0.1] PHP Warning: mkdir(): Permission denied in /var/www/html/upload on line 33, referer: https://mywebsite.com/referer
解决方案The answer is staring right in front of me, but I miss it due to my unfamiliarity with SELinux.
The SELinux context type should be set as
httpd_sys_content_rw_t
instead ofhttpd_sys_content_t
so that the folder is both readable and writable for apache. Changing the context recursively is done with the following command:# chcon -R -t httpd_sys_content_rw_t /var/www/html/images
Good grief. Hope it helps others who come across this.
这篇关于PHP无法用mkdir目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!