---
title: "Linux下无图形化配置万维网服务器httpd"
author: "shellfish"
date: "2010-01-17T10:26:33Z"
tags: []
categories: ["操作系统"]
slug: "linux-httpd"
draft: false
lastmod: "2013-02-18T13:46:43Z"
id: 572593
url: "https://shellfish.iteye.com/blog/572593"
---

1，启动服务并设置为自启动：

\[simonsun@host ~]$ sudo /etc/rc.d/init.d/httpd start  
\[simonsun@host ~]$ cd /etc/rc.d/init.d/  
\[simonsun@host init.d]$ sudo /sbin/chkconfig --add httpd  
\[simonsun@host init.d]$ sudo /sbin/chkconfig --level 35 httpd on

2，为了外网能够访问，添加80端口为允许访问的端口到防火墙：  
\[simonsun@host ~]$ sudo vim /etc/sysconfig/iptables.conf  
添加：  
\-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  
到  
\-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited  
之前。  
参考链接：http://looklookme.blog.51cto.com/470472/104231

注：CentOS 6 下：

\[simon\_sun@gnu init.d]$ sudo vim **/etc/sysconfig/iptables**  
iptables         iptables-config  iptables.old

添加：**-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT**

添加后如下:

\# Firewall configuration written by system-config-firewall  
\# Manual customization of this file is not recommended.  
\*filter  
:INPUT ACCEPT \[0:0]  
:FORWARD ACCEPT \[0:0]  
:OUTPUT ACCEPT \[0:0]  
\-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT  
\-A INPUT -p icmp -j ACCEPT  
\-A INPUT -i lo -j ACCEPT  
\-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT  
\-A INPUT -j REJECT --reject-with icmp-host-prohibited  
\-A FORWARD -j REJECT --reject-with icmp-host-prohibited  
COMMIT

 另外，centos5系列的图形化配置工具命令是system-config-securitylevel，含有防火墙和selinux，现在最新的6系列下的命令是system-config-firewall，并且没有设置selinux的地方，需要用命令setenforce和getenforce来设置和查看。

3，另外，默认的存储页面的目录是 /var/www/html，可以修改为自定义的路径：  
\[simonsun@host ~]$ sudo vim /etc/httpd/conf/httpd.conf  
把 DocumentRoot "/var/www/html" 注释掉，修改成自定义的：  
#DocumentRoot "/var/www/html"  
DocumentRoot "/home/webpages"  
然后相应的建立目录，修改权限，添加当前用户到apache组，并让组成员能够修改文件，方便添加文件。重启动httpd服务：

\[simonsun@host ~]$ sudo /usr/sbin/usermod -G apache -a simonsun

(或者把运行httpd的用户apache添加到simonsun所属的用户组simon也可以，日后如果有其他用户写的文件也需要被httpd访问到，添加到simonsun所属的用户组simon就可以了，当然得设置权限为chmod g+rx：

sudo /usr/sbin/usermod -G simon -a apache )

 

这一步执行后需要注销一下当前登录的pts，或者注销xwindow桌面。  
\[simonsun@host ~]$ sudo mkdir /home/webpages  
\[simonsun@host ~]$ sudo chown apache.simonsun /home/webpages/ -Rf  
\[simonsun@host ~]$ sudo chmod ug+rwx /home/webpages/ -Rf  
\[simonsun@host ~]$ sudo chmod o+rx /home/webpages/ -Rf

\[simonsun@host ~]$ sudo /etc/rc.d/init.d/httpd restart

ok！