1、安装httpd [root@localhost ~]# yum -y install httpd 2、查看安装后生成的配置文件(略) [root@localhost ~]# rpm -ql httpd |more 3、由于Apache受到selinux的影响,所以需要把selinux关闭(临时|永久) [root@localhost ~]# getenforce Enforcing [root@localhost ~]# setenforce 0 [root@localhost ~]# getenforce Permissive [root@localhost ~]# vim/etc/sysconfig/selinux
为了演示方便,这里也把iptables防火墙关闭(临时|永久) [root@localhost ~]# service iptables stop iptables:清除防火墙规则: [确定] iptables:将链设置为政策 ACCEPT:filter [确定] iptables:正在卸载模块: [确定] [root@localhost ~]# chkconfig iptables off [root@localhost ~]# chkconfig --list |grepiptables iptables 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 4、启动Apache [root@localhost ~]# service httpd start 正在启动 httpd:httpd: Could not reliably determine the server's fully qualifieddomain name, using localhost.localdomain for ServerName [确定] [root@localhost ~]# netstat -tulanp |grep:80 tcp 0 0 :::80 :::* LISTEN 2167/httpd [root@localhost ~]# lsof -i tcp:80 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME httpd 2167 root 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2169 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2170 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2171 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2172 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2173 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2174 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2175 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) httpd 2176 apache 4u IPv6 15486 0t0 TCP *:http (LISTEN) [root@localhost ~]# ps aux |grep http root 2167 0.0 0.3 173484 3744 ? Ss 15:43 0:00 /usr/sbin/httpd apache 2169 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2170 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2171 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2172 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2173 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2174 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2175 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd apache 2176 0.0 0.2 173484 2388 ? S 15:43 0:00 /usr/sbin/httpd root 2181 0.0 0.0 103240 864 pts/0 S+ 15:44 0:00 grep http 5、客户端访问
7、关于欢迎页面信息的调整 [root@localhost ~]# cd /etc/httpd/ [root@localhost httpd]# pwd /etc/httpd [root@localhost httpd]# tree conf.d/ conf.d/ ├── README └── welcome.conf #此处就是Apache服务器默认欢迎页面 0 directories, 2 files [root@localhost ~]# cd /etc/httpd/conf.d/ [root@localhost conf.d]# ll 总用量 8 -rw-r--r--. 1 root root 392 8月 14 2013 README -rw-r--r--. 1 root root 299 8月 2 2013 welcome.conf [root@localhost conf.d]# mvwelcome.conf `date +%F`welcomeconf [root@localhost conf.d]# ll 总用量 8 -rw-r--r--. 1 root root 299 8月 2 2013 2014-03-13welcomeconf -rw-r--r--. 1 root root 392 8月 14 2013 README [root@localhost conf.d]# service httpdreload 重新载入 httpd: 客户端访问验证信息:
8、接下来我们就配置网站的基本页面玩玩呗。 [root@localhost ~]# cd /var/www/html/ [root@localhost html]# ll 总用量 0 [root@localhost html]# echo"<h1>Welcom to my website</h1>" >index.html 客户端访问验证
9、配置文件说明 [root@localhost ~]# grep"Section" /etc/httpd/conf/httpd.conf ### Section 1: Global Environment ### Section 2: 'Main' server configuration ### Section 3: Virtual Hosts 注:httpd配置文件共分为3段,第一段为全局段配置,即在此里面的设置对整个配置文件都生效,第二段为主配置文件段,也是默认的第三段位虚拟主机配置段; 尤其需要注意的是第二段和第三段不能同时启用,否则会发生冲突。 事先备份好配置文件,养成良好的习惯 [root@localhost ~]# cd /etc/httpd/conf [root@localhost conf]# pwd /etc/httpd/conf [root@localhost conf]# ls httpd.conf magic [root@localhost conf]# cp httpd.conf `date+%F`httpd_conf [root@localhost conf]# ll 总用量 88 -rw-r--r--. 1 root root 34418 3月 13 16:04 2014-03-13httpd_conf -rw-r--r--. 1 root root 34418 8月 2 2013 httpd.conf -rw-r--r--. 1 root root 13139 8月 14 2013 magic [root@localhost conf]# pwd /etc/httpd/conf [root@localhost conf]# egrep -v "^.*#| ^$" httpd.conf |wc -l 574 去除Apache的注释信息,Apache的默认有效配置文件就几十行,且大部分都是没有用的。 过滤掉以任意多个字符及#开头的行及空行
待续——————————————————————————————————————————