Centos 7 Selinux问题我想? PHP无法读取或写入

我的Web应用程序有一个上传文件夹: /disk2/app/uploads

ls -Z返回:

 drw-r--r--. apache apache unconfined_u:object_r:httpd_sys_rw_content_t:s0 uploads 

ls -Z /返回:

 drwxrwxrwx. root root system_u:object_r:file_t:s0 disk2 

ls -Z /disk2返回:

 drwxr-xr-x. apache apache unconfined_u:object_r:file_t:s0 app 

其中很多我从这里得到

当我在php中运行is_writable('/disk2/app/uploads') ,它返回false

我已经尝试了所有我能想到的可能性。

相关的审计日志:

 type=AVC msg=audit(1510944045.012:202923): avc: denied { getattr } for pid=14017 comm="httpd" path="/disk2/app/uploads/12222/206/1496103427-20170526_151922.jpg" dev=sdb ino=17826039 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:file_t:s0 tclass=file type=AVC msg=audit(1510944045.012:202924): avc: denied { write } for pid=14017 comm="httpd" name="uploads" dev=sdb ino=2097155 scontext=unconfined_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:file_t:s0 tclass=dir 

您需要configurationSELinux文件上下文,以便在创build文件时正确设置它们。 通常的文件,inheritance父目录的fcontext,所以你需要正确的指定。 就像是

 semanage fcontext -a -t httpd_sys_rw_content_t "/disk2/app/uploads(/.*)?" restorecon -Rv /disk2/app/uploads 

应该诀窍。