[apache linux使用手册]linux+apache启动提示"Document root must be a directory"

更新时间:2017-08-20    来源:apache    手机版     字体:

【www.bbyears.com--apache】

解决办法:

方法一:

把目录或文件的策略类型改成 httpd_sys_content_t 就可以了。
# chcon  -R -h -t httpd_sys_content_t  /www/web/
然后可以用 ls -laZ 命令查看文件目录的策略类型。


方法二:

禁用SELinux
linux系统貌似还有个SElinux安全机制,查看一下状态吧。

[root@localhost home]# getenforce

Enforcing

果然SElinux被开启了,而且还是强制模式。

目录被设成了user_home_t类型,apache的进程没有权限,无法访问。

针对Apache的进程所使用的SELinux target policy规定了apache的进程只能访问httpd_sys_content_t类型的目录或文件。所以只要修改相关的权限就可以了。 解决办法:

1.更改文件夹权限

chcon  -t httpd_sys_content_t /home/www/

chcon  -t httpd_sys_content_t /home/www/html/

然后ls -Z查看目录权限

看,权限被改为httpd_sys_content_t了吧。这样就可以启动httpd了。

2.关闭SElinux关闭SElinux的话需要重启系统,

修改方法为:vi /etc/selinux/config修改SELINUX=disabled

然后重启系统就关闭SElinux了。

另外一篇参考文章:

apache提示DocumentRoot must be a directory

系统环境:Scientific Linux release 6.2

将DocumentRoot改为 /home/godontop/www 后提示:

Starting httpd: Syntax error on line 293 of /etc/httpd/conf/httpd.conf:
DocumentRoot must be a directory

[root@sl ~]# getsebool -a |grep httpd_enable_homedirs 

httpd_enable_homedirs --> off

原来是SELinux不允许使用home目录作为web目录!

修改 SELinux 设定

view sourceprint?1 [root@sl ~]# setsebool httpd_enable_homedirs on

之后重启apache,一切正常

[root@sl ~]# service httpd restart 

Stopping httpd:                                            [  OK  ] 

Starting httpd:                                            [  OK  ]

本文来源:http://www.bbyears.com/jiaocheng/34987.html

热门标签

更多>>

本类排行