LAMP之Apache生產服務實戰指南之基本安裝配置說明yum版

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

wKiom1NLsATRmwRwAAGMRDhfeg8303.jpg

爲了演示方便,這裏也把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、客戶端訪問

wKioL1NLsA-AEOX3AAHgjFnHWqk687.jpg

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:
客戶端訪問驗證信息:

wKioL1NLsDmDWe89AAFVuVFTtOU049.jpg

8、接下來我們就配置網站的基本頁面玩玩唄。
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ll
總用量 0
 [root@localhost html]# echo"<h1>Welcom to my website</h1>" >index.html 
客戶端訪問驗證

wKiom1NLsIXBQ3nSAAEkuwCb_uE158.jpg

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的默認有效配置文件就幾十行,且大部分都是沒有用的。
過濾掉以任意多個字符及#開頭的行及空行

待續——————————————————————————————————————————


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章