Ferrets家的Wordpress

杂记

permission

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, 权限, 读写

搜索站点

日历

2023年 3月
一二三四五六日
 12345
6789101112
13141516171819
20212223242526
2728293031 
« 1月    

分类

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

近期文章

  • 使用OPNsense来保护内网的服务
  • Mikrotik RB750Gr3优化配置,跑(差点)满千兆
  • 用smartdns来防治DNS污染
  • Proxmox中LXC容器中docker调用宿主机的显卡加速
  • Linux上iptables端口触发拦截
  • 通过DHCP指定mtu
  • openwrt 国内镜像源
  • 为RDP启用显卡加速,提升远程桌面效果
  • 为proxmox启用intel核显的虚拟化
  • windows无法解析域名

友链

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

归档

管理

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

Copyright © 2023 Ferrets家的Wordpress.

Omega WordPress Theme by ThemeHall