WEB伺服器的架設,在linux有一個很著名的架構叫lamp:linux+apache+mysql+php
Apache一直是Internet上最流行的Web伺服器
後台進程:httpd
指令碼:/etc/rc.d/init.d/httpd
使用連接埠:80(http),443(https)
所需RPM包:httpd
配置路徑:/etc/httpd/*
預設網站存放路徑:/var/www/*
apache主要目錄和檔案說明
主設定檔位置/etc/httpd/conf/*或者/usr/local/apache2/conf/httpd.conf
啟動指令碼/etc/rc.d/init.d/httpd
格式的協助文檔/usr/local/apache2/manual/*html
用在html網頁中的表徵圖檔案/usr/local/apache2/icons/*
建立和更新apache使用者的程式/usr/local/apache2/htpasswd
http伺服器程式/usr/sbin/httpd
記錄檔/usr/local/apache2/
優點:免費,穩定,速度快
我們先安裝apache
rpm -ivh httpd-2.2.3-31.el5.centos.i386.rpm
mv httpd-2.0.54 apache
cd apache
./configure --prefix=/usr/local/apache2 --enable-module=so
make
make install
安裝apache至/usr/local/apache 並配置apache支援dso方式
查看一下安裝Apache的情況
[root@host CentOS]# rpm -qa | grep httpd
httpd-2.2.3-31.el5.centos
httpd-manual-2.2.3-31.el5.centos
system-config-httpd-1.3.3.3-1.el5
安裝好了,啟動Apache,
[root@host CentOS]# service httpd start
現在就可以先看看這個服務帶給我們的是什麼,因為做這個實驗應該可以DNS服務實驗一起,但是時間的問題沒有在一起做,訪問WEB服務的時候,我們沒有用網域名稱伺服器,只是對應WEB伺服器的IP地址
要想網頁上渡口自己想配置的內容就要來配置Apache,我們繼續一步一步的來配置他!!!
這是apache的所有設定檔存放的目錄
[root@host ~]# ll /etc/httpd/
總計 28
drwxr-xr-x 2 root root 4096 11-04 17:08 conf
drwxr-xr-x 2 root root 4096 11-04 17:09 conf.d
lrwxrwxrwx 1 root root 19 11-04 17:08 logs -> ../../var/log/httpd
lrwxrwxrwx 1 root root 27 11-04 17:08 modules -> ../../usr/lib/httpd/modules
lrwxrwxrwx 1 root root 13 11-04 17:08 run -> ../../var/run
這是網頁檔案存放目錄,一般在html內
[root@host ~]# ll /var/www/
總計 48
drwxr-xr-x 2 root root 4096 2009-09-04 cgi-bin
drwxr-xr-x 3 root root 4096 11-04 17:08 error
drwxr-xr-x 2 root root 4096 2009-09-04 html
drwxr-xr-x 3 root root 4096 11-04 17:08 icons
drwxr-xr-x 14 root root 4096 11-04 17:09 manual
drwxr-xr-x 2 webalizer root 4096 11-04 17:08 usage
[root@host ~]# ll /var/www/html/
總計 0
apache的主設定檔
[root@host ~]# vim /etc/httpd/conf/httpd.conf
httpd.conf中每行包含一條語句,行末使用反斜線“\”可以換行,但是反斜線與下一行中間不能有任何其他字元(包括空白)
httpd.conf的配置語句除了選項的參數值以外,所有選項指令均不區分大小寫,可以在每一行前用“#”號表示注釋。
全域配置的相關參數,全域的參數一般不用改哦
ServerType
選擇系統啟用伺服器的方式。可以是inetd或standalone
預設應該是獨立的stationalone
ServerRoot
設定Apache 安裝的絕對路徑
#
ServerRoot "/etc/httpd"
TimeOut
設定 伺服器接收至完成的最長等待時間
#
Timeout 120
KeepAlive
設定伺服器是否開啟連續請求功能,真實伺服器一般都要開啟
#
KeepAlive Off
MaxKeepAliveRequests
設定伺服器所能接受的最大連續請求量
#
MaxKeepAliveRequests 100
#
KeepAliveTimeout 15 \\使用者‘連續’請求的等待時間上限數
##
## Server-Pool Size Regulation (MPM specific)
##
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork.c>
StartServers 8 \\設定啟用時所需建立的子進程數
MinSpareServers 5 \\設定最小閑置子進程數
MaxSpareServers 20 \\設定最大閑置子進程數
ServerLimit 256
MaxClients 256 \\設定同時能夠提供使用者的最大服務要求數
MaxRequestsPerChild 4000
</IfModule>
Port
設定http服務的預設連接埠。
User/Group
設定 伺服器程式的執行者與屬組
#
User apache
Group apache
我們說過,網頁檔案預設是放在/var/www/html中的,我們現在就自己去寫個網頁,簡單的,來測試下
[root@host ~]# ll /var/www/html/
總計 0
[root@host ~]# echo hello,this is my home,welcome! > /var/www/html/index.html
[root@host ~]# ll /var/www/html/
總計 8
-rw-r--r-- 1 root root 48 02-19 10:50 index.html
[root@host ~]# cat /var/www/html/index.html
hello,this is my home,welcomell!
然後重新訪問你的伺服器,看看有什麼變化
在主設定檔(/etc/httpd/conf/httpd.conf)中,看見DirectoryIndex了麼,這個位置就是定義首頁檔案的名字的,自己可以隨意修改,但是一般網頁開發都寫成了index.html,index.htm default.html 等等
#
DirectoryIndex index.html index.html.var
我們按照自己的想法構架一個PHP WEB網站。。。GO。。。
添加了一個index.php ,方便一會我們測試apache支援php,如果找不到,系統會出現redhat的測試頁面
#
DirectoryIndex index.html index.php
我們測試把預設網站目錄改到root家目錄下
第一步,修改DocumentRoot這個位置 1
第二步,修改目錄的使用權限設定 2
重啟一下httpd服務
[root@host webphp]# service httpd restart
用戶端瀏覽
現在我們自己建一個PHP頁面吧。。。
[root@host webphp]# ll /root/webphp
總計 0
[root@host webphp]# echo hello.This is a php webservers! > /root/webphp/index.php
[root@host webphp]# ll /root/webphp
總計 8
-rw-r--r-- 1 root root 32 02-19 13:58 index.php
我們來看看我們自己建的PHP頁面吧。。。
基於LINUX下的基本服務構架都實驗過了!但是對於構架好後的正常維護,還需要有更好的環境去努力學習啊。。。
-------------------