CentOS Linux系统下更改Apache默认网站目录

引言:

Apache默认的网站目录是在/var/www/html,我们现在要把网站目录更改到/home/wwwroot/web,操作如下

准备工作:

创建目录:

cd /home

mkdir wwwroot

cd wwwroot

mkdir web

touch index.php

操作步骤:

1、vi /etc/httpd/conf/httpd.conf

找到 DocumentRoot "/var/www/html" 这一段 #apache的根目录

把/var/www/html 这个目录改为/home/wwwroot/web

再找到 <Directory "/var/www/html"> #定义apache /var/www/html这个区域

把 /var/www/html改成/home/wwwroot/web

这样我们就把apahce的默认路径改掉了

service httpd restart #重启Apache服务器

2、访问localhost的时候,会发现访问拒绝,这是为什么呢?

主要是因为你的/home/wwwroot/web的权限是750,apache这个用户没有权限访问,你需要更改掉权限,可以这样改

chmod -R 755 /home/wwwroot/web

然后去访问 发现正常运行了(apache的用户:apache 运行apache的组:apache)

至此,Apache默认网站目录更改成功。