PHP 无法使用 mkdir 创建目录 [英] PHP unable to create a directory with mkdir
问题描述
我有一个以前工作的 PHP 脚本,它能够使用 mkdir
创建一个目录:
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);
我对文件夹 /var/www/html/images
的权限设置进行了一些更改,现在是:
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
我认为以前这个文件夹是由 apache
所有的.但是由于apache
作为一个用户组具有读、写和执行的全部权限,我想知道为什么它不能在其中创建一个文件夹.使用 mkdir
会产生一个 false
布尔值.
I think previously this folder was owned by apache
. But since apache
has the full privileges of read, write and execute as a user group, I wonder why it can't create a folder within. Using the mkdir
produces a false
boolean value.
问题是由于目录所有权还是有其他原因?请注意,我使用的是 PHP 5.4 版.
Is the problem due to directory ownership or is there some other reasons? Note that I am using PHP version 5.4.
错误日志已添加:
[Mon Dec 17 11:12:34 2012] [error] [client 127.0.0.1] PHP 警告:mkdir():第 33 行/var/www/html/upload 中的权限被拒绝,推荐人:https://mywebsite.com/referer
[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
推荐答案
答案就在眼前,但由于我对 SELinux 不熟悉,我错过了.
The answer is staring right in front of me, but I miss it due to my unfamiliarity with SELinux.
SELinux 上下文类型应设置为 httpd_sys_content_rw_t
而不是 httpd_sys_content_t
,以便该文件夹对 apache 可读可写.使用以下命令以递归方式更改上下文:
The SELinux context type should be set as httpd_sys_content_rw_t
instead of httpd_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屋!