CentOS安裝Apache詳解

有時候安裝Apache會碰到apr not found的解決方法,請看下面鏈接文章

http://blog.sina.com.cn/s/blog_61c07ac501017pb9.html 


言歸正傳,開始

安裝HTTP(Apache)服務器及相關組件

安裝Apache服務器及相關組件

[root@sample ~]# yum -y install httpd\*  ← 在線安裝httpd

爲了使服務器開通HTTP服務後能夠運行PHP編寫的交互程序

[root@sample ~]# yum -y install php\*  ← 在線安裝PHP 

爲了使PHP應用程序的執行效率大幅度提高需要安裝Zend

[root@sample~]#wget http://downloads.zend.com/optimizer/3.0.1/ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz  ← 下載Zend的源代碼
[root@sample ~]# tar zxvf ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz  ← 展開被壓縮的源代碼
[root@sample ~]# cd ZendOptimizer*   ← 進入Zend的源代碼目錄
[root@sample ZendOptimizer-3.0.1-linux-glibc21-i386]# ./install.sh  ← 運行安裝腳本

配置HTTP(Apache)服務器


接下來,爲了使服務器更安全以及更加符合實際要求,對默認的設置進行一些必要的更改。尤其在一些細節方面,越少向外界透露服務器的信息,就越能保證服務器的安全。
[root@sample ~]# vi etc/httpd/conf/httpd.conf  ← 編輯Apache的配置文件
ServerTokens OS  ← 找到這一行,將“OS”改爲“Prod”(在出現錯誤頁的時候不顯示服務器操作系統的名稱)
 ↓
ServerTokens Prod   ← 變爲此狀態
ServerSignature On  ← 找到這一行,將“On”改爲“Off”
 ↓
ServerSignature Off  ← 在錯誤頁中不顯示Apache的版本
ServerAdmin root@localhost  ← 將管理員郵箱設置爲自己常用的郵箱
 ↓
ServerAdmin [email protected]  ← 根據實際情況修改默認設置
#ServerName new.host.name:80  ← 修改主機名
 ↓
ServerName www.centospub.com:80  ← 根據實際情況修改,端口號保持默認的80
Options Indexes FollowSymLinks  ← 找到這一行,刪除“Indexes”,並添加“Includes”、“ExecCGI”
 ↓
Options Includes ExecCGI FollowSymLinks  ← 允許服務器執行CGI及SSI
#AddHandler cgi-script .cgi  ← 找到這一行,去掉行首的“#”,並在行尾添加“.pl”
 ↓
AddHandler cgi-script .cgi .pl  ← 允許擴展名爲.pl的CGI腳本運行
AllowOverride None  ← 找到這一行,將“None”改爲“All”
 ↓
AllowOverride All  ← 變爲此狀態,允許.htaccess
LogFormat “%h %l %u %t \”%r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined  ← 找到這一行
 ↓
LogFormat “%h %l %u %t \”%!414r\” %>s %b \”%{Referer}i\” \”%{User-Agent}i\”" combined  ← 改爲此狀態(添加“!414”到規則中,對於過長的日誌不記錄)
AddDefaultCharset UTF-8  ← 找到這一行,在行首添加“#”
 ↓
#AddDefaultCharset UTF-8  ← 不使用UTF-8作爲網頁的默認編碼
AddDefaultCharset GB2312  ← 並接着添加這一行(添加GB2312爲默認編碼)
<Directory “/var/www/icons”>  ← 找到這一個標籤,並在標籤中更改相應選項
  Options Indexes MultiViews  ← 找到這一行,將“Indexes”刪除
    ↓
  Options MultiViews   ← 變爲此狀態(不在瀏覽器上顯示樹狀目錄結構)
[root@sample ~]# rm -f /etc/httpd/conf.d/welcome.conf /var/www/error/noindex.html  ← 刪除測試頁

啓動HTTP服務
[root@sample ~]# chkconfig httpd on  ← 設置HTTP服務自啓動
[root@sample ~]# chkconfig –list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off   ← 確認2–5爲on的狀態就OK
[root@sample ~]# /etc/rc.d/init.d/httpd start  ← 啓動HTTP服務
Starting httpd:              [ OK ] ← 啓動成功會出現OK
如果啓動失敗的話,會出現錯誤信息。原因可能是因爲httpd.conf文件編輯過程中的失誤,請檢查httpd.conf。

對HTTP服務進行簡單測試
[root@sample ~]# echo hello >> /var/www/html/index.html  ← 建立測試頁

刪除剛剛建立的測試頁
[root@sample ~]# rm -f /var/www/html/index.html  ← 刪除測試頁

對HTTP服務進行全面測試

[1] 對HTML格式網頁正確顯示的測試
[root@sample ~]# vi /var/www/html/index.html  ← 建立測試頁,內容如下:
<html>
< head>
< meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″>
< title>Hello,World!</title>
< body>
Hello,World!
< /body>
< /html>

在瀏覽器中輸入“http://服務器IP地址”或者“http://你的域名”,如果出現“Hello,World!”,並且瀏覽器讀取編碼爲簡體中文,就OK。

[2] 對CGI的支持進行測試
[root@sample ~]# vi /var/www/html/test.cgi  ← 建立CGI測試頁,內容如下:
#!/usr/bin/perl
print “Content-Type: text/html\n\n”;
print “<html><body>”;
print “Hello,World!CGI is working!<br>”;
print “</body></html>”;

[root@sample ~]# chmod 755 /var/www/html/test.cgi   ← 然後將CGI測試文件屬性設置爲755
在瀏覽器中輸入“http://服務器IP地址/test.cgi”或者“http://你的域名/test.cgi”,如果正確顯示“Hello,World!CGI is working!”,說明對於CGI的支持沒有問題。

[3] 對PHP的支持進行測試
[root@sample html]# vi /var/www/html/test.php  ← 建立PHP測試文件,內容如下:
<?php
phpinfo();
?>

在瀏覽器中輸入“http://服務器IP地址/test.php”或者“http://你的域名/test.php”後,正確的顯示出了服務器上PHP的詳細信息,說明對PHP可以正確的支持。

[4] 對SSI進行測試
[root@sample ~]# vi /var/www/html/test.shtml  ← 建立SSI測試頁,內容如下:
<html>
< head>
< meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″>
< title>Hello,World!</title>
< body>
TEST SSI
< !–#config timefmt=”%Y/%m/%d %H:%M:%S” –>
< !–#echo var=”DATE_LOCAL” –>
< /body>
< /html>

在瀏覽器中輸入“http://服務器IP地址/test.shtml”或者“http://你的域名/test.shtml”,如果正確顯示當時的日期和時間,說明對於SSI的支持沒有問題。

[5] 對.htaccess的支持進行測試
[root@sample ~]# vi /var/www/html/index.shtml  ← 建立.htaccess測試用的頁,內容如下:
<html>
< head>
< meta http-equiv=”Content-Type” content=”text/html; charset=GB2312″>
< title>Hello,World!</title>
< body>
The name of the file is <!–#echo var=”DOCUMENT_NAME” –>
< /body>
< /html> 

在瀏覽器中輸入“http://服務器IP地址”或者“http://你的域名”,如果顯示“Forbidden”,說明.htaccess正常。

[6]建立一個.htaccess文件,並定義相應規則,如下:
[root@sample html]# vi /var/www/html/.htaccess  ← 建立.htaccess文件,內容如下:

DirectoryIndex index.shtml
在瀏覽器中輸入“http://服務器IP地址”或者“http://你的域名”,如果正確顯示“ The name of the file is index.shtml”,說明.htaccess中的規則生效狀態,OK。
Apache 日誌文件
[root@sample html]#vi /var/log/httpd/error_log ← Apache 日誌文件



原文地址:http://www.cnyunwei.com/forum.php?mod=viewthread&tid=9053



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