CentOS6.5安裝Apache服務

來源:互聯網
上載者:User

CentOS6.5安裝Apache服務

一、描述

CentOS安裝Apache服務可以有兩種方式,一種是用yum安裝,一種是從官網下載原始碼進行安裝。

二、使用yum安裝Apache服務

步驟1:在命令列輸入如下語句可以使用yum線上更新方式進行安裝:

[tong@tong /]$ sudo yum install httpd -y

注意:採用該方式進行安裝設定檔的預設路徑為:/etc/httpd/conf/httpd.conf

步驟二:配置防火牆,添加下面紅色字型的一行,表示開啟80連接埠供客戶瀏覽。

[tong@tong /]$ sudo vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -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 22 -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

步驟三:配置完防火牆之後需要重新啟動防火牆

[tong@tong /]$ sudo service iptables restartiptables: Setting chains to policy ACCEPT: filter [ OK ]iptables: Flushing firewall rules: [ OK ]iptables: Unloading modules: [ OK ]iptables: Applying firewall rules: [ OK ]

步驟四;Apache配置完成後,則可啟動服務

[tong@tong /]$ sudo service httpd startStarting httpd: httpd: apr_sockaddr_info_get() failed for tonghttpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName[ OK ]

注意:雖然這裡可以啟動但是報錯,這是因為沒有在Apache伺服器的設定檔中添加ServerName參數,所以我們要在設定檔中配置這個參數

步驟5:我們查看我們的hostname主機名稱,並將該主機名稱添加到Apache設定檔的ServerName參數中

[tong@tong /]$ hostnametong[tong@tong /]$ cat /etc/sysconfig/networkNETWORKING=yesHOSTNAME=tong

由上述的hostname為tong,則編輯Apache設定檔

[tong@tong conf]$ sudo vi /etc/httpd/conf/httpd.conf

在其中加入一行:ServerName tong:80

步驟5:重新啟動Apache服務,則不會報錯

[tong@tong conf]$ sudo service httpd restartStopping httpd: [ OK ]Starting httpd: [ OK ]

步驟6:測試範例網頁

在本機瀏覽器輸入:http://本機IP地址,我的IP為:192.168.200.5,,我在瀏覽器上輸入:http://192.168.200.5

結果顯示:


 

三、使用原始碼安裝Apache服務

步驟1:下載原始碼檔案

[tong@tong tongSoftware]$ sudo wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.12.tar.gz

步驟2;解壓並安裝

[tong@tong tongSoftware]$ sudo tar xzvf httpd-2.4.12.tar.gz

進入該解壓後的目錄,輸入如下命令:

[tong@tong httpd-2.2.29]$ sudo ./configureconfigure: error: in `/usr/local/tongSoftware/httpd-2.2.29/srclib/apr':configure: error: no acceptable C compiler found in $PATHSee `config.log' for more detailsconfigure failed for srclib/apr

系統提示未安裝gcc編譯器,則安裝該編譯器

[tong@tong httpd-2.2.29]$ sudo yum install gcc

安裝成功後重新編譯源檔案:

[tong@tong httpd-2.2.29]$ sudo ./configure //檢查安裝平台是否支援安裝

[tong@tong httpd-2.2.29]$ sudomake //根據安裝平台進行編譯

[tong@tong httpd-2.2.29]$ sudomake install //安裝軟體

然後按照之前用yum安裝的方法配置防火牆,啟動Apache服務。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.