Ferrets家的Wordpress

readwrite

CentOS用apache当web服务器时出现的权限问题

2016年12月10日 by Ferrets Leave a Comment

参考:https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

一般的文件读写权限,所属用户和组这些先不讨论,毕竟这些相关的文档太多,也相对基础了点。这里记录的是CentOS种由SELinux引起的权限问题。

刚在家重新搭建了owncloud,这时候出现了一个非常诡异的权限问题,文件和文件夹的所有权都是apache(CentOS中默认的所属用户和用户组),但是访问owncloud的安装程序的时候却提示没有写权限。我试过用sudo切换到apache用户来执行touch创建文件,没问题,甚至写一个简易的php脚本来测试文件的读写,都没有遇到权限的问题,但是在使用浏览器访问的时候,php脚本就遇到了权限的问题。

经过一番Google,确定时SELinux的问题。

用ls -Z可以看到一些额外的属性,像这样

drwxr-xr-x. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 application
-rw-r--r--. apache apache unconfined_u:object_r:httpd_sys_content_t:s0 index.php
修复的办法是
# SELinux serve files off Apache, resursive
sudo chcon -t httpd_sys_content_t /data/www/html/sites/mysite -R
# Allow write only to specific dirs
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/logs -R
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/uploads -R

httpd_sys_content_t – 允许apache读取文档
httpd_sys_rw_content_t – 允许apache读写文档
更加详细的标记说明,可以参考https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Managing_Confined_Services/sect-Managing_Confined_Services-The_Apache_HTTP_Server-Types.html

Posted in: 网络 Tagged: CentOS, permission, readwrite, Redhat, SELinux, 权限, 读写

日历

2021年4月
一二三四五六日
 1234
567891011
12131415161718
19202122232425
2627282930 
« 2月    

分类

  • Android
  • docker
  • Linux
  • OpenWrt
  • PHP
  • RaspberryPi
  • RouterOS
  • Windows
  • 吐槽
  • 搭建服务
  • 未分类
  • 生活
  • 网络

近期文章

  • windows无法解析域名
  • 在openwrt路由上运行shairplay作为远程音箱
  • 建立私有docker镜像源
  • RouterOS上抵挡扫描的防火墙策略
  • Windows Server作为Mikrotik设备管理员的3A服务器
  • 使用ipv6连接Proxmox VE
  • 根据audit.log来放通SELinux的拦截
  • 使用PXE从NFS服务器启动Debian Linux
  • 在运行ArchlinuxARM的PogoPlug上打开CPU的AES硬件加速
  • 增大mysql/mariadb的最大连接数

友链

  • ntzyz's space
  • Openwrt中文论坛
  • SNGR
  • Trevikids行止由心
  • 煎蛋

文章归档

功能

  • 登录
  • 条目feed
  • 评论feed
  • WordPress.org

Copyright © 2021 Ferrets家的Wordpress.

Beta WordPress Theme by themehall.com