CentOS下安裝Apache步驟詳解

來源:互聯網
上載者:User

標籤:centos、apache、apr、apr-util、pcre


CentOS下安裝Apache步驟詳解

一、實驗環境

    Linux: CentOS release 6.7 (Final)

    Apache: httpd-2.4.23.tar.gz

    VMware: VMware 10.0

    宿主機: Win10 x64

二、Apache介紹

Apache一款 Web伺服器軟體。它可以運行在幾乎所有廣泛使用的電腦平台上,由於其跨平台和安全性被廣泛使用,是最流行的Web伺服器端軟體之一。它快速、可靠並且可通過簡單的API擴充,將Perl/Python等解譯器編譯到伺服器中。同時Apache音譯為阿帕奇,是北美印第安人的一個部落,叫阿帕奇族。

三、安裝包下載及其環境要求

Apache所需依賴環境有 apr、apr-util、pcre,還有編譯源碼需要的gcc和gcc-c++,所示安裝包和我使用的版本

安裝包

我下載使用的版本

apache

http://httpd.apache.org/download.cgi

httpd-2.4.23.tar.gz

apr

http://apr.apache.org/

apr-1.5.2.tar.gz

apr-util

http://apr.apache.org/

apr-util-1.5.4.tar.gz

pcre

http://www.pcre.org/

pcre-8.39.tar.gz

注意:gcc和gcc-c++使用rpm或者yum方式安裝,pcre下載的時候一定要看清楚是pcre還是pcre2,因我下載了pcre2,安裝了好幾次都失敗,最後發現是因為安裝包下載錯誤。

強烈建議看一下官方文檔:http://httpd.apache.org/docs/2.4/install.html

四、安裝過程

1、配置CentOS-Base.repo, 安裝gcc、gcc-c++配置網路yum源的方法(http://blog.chinaunix.net/uid-23683795-id-3477603.html),配置完成後執行:

[[email protected]~]# yum -y install gcc

[[email protected]~]# yum -y install gcc-c++

2、安裝依賴包和Apache HTTPServer

2.1使用FTP工具上傳httpd、apr、apr-util、pcre壓縮包至/usr/local/mypackages/

[[email protected]~]# cd /usr/local/mypackagers/

[[email protected]]# ls

apr-1.5.2.tar.gzapr-util-1.5.4.tar.gz httpd-2.4.23.tar.gz pcre-8.39.tar.gz

2.2安裝apr:

[[email protected]]# tar xvf apr-1.5.2

[[email protected]]# cd apr-1.5.2

[[email protected]]#./configure --prefix=/usr/local/apr

[[email protected]]#make && install

2.3安裝apr

[[email protected]]# tar xvf apr-util-1.5.4.tar.gz

[[email protected]]# cd apr-util-1.5.4

[[email protected]]#./configure --prefix=/usr/local/apr-util--with-apr=/usr/local/apr

[[email protected]]#make && install

2.3安裝pcre

[[email protected]]# tar xvf pcre-8.39.tar.gz

[[email protected]]# cd pcre-8.39

[[email protected]]# ./configure --prefix=/usr/local/pcre

[[email protected]]# make && make install

2.4安裝httpd

[[email protected]]#tar xvf httpd-2.4.23.tar.gz

[[email protected]]# cd httpd-2.4.23

[[email protected]]# ./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre/

[[email protected]]#make && make install

五、啟動和設定開機自啟

1、開放80連接埠或關閉防火牆,詳見下面防火牆配置,啟動apache服務:

    [[email protected] ~]# /usr/local/apache/bin/apachectl start,瀏覽器輸入:http://IP地址:80,出現It works!證明Apache已經安裝成功。

2、設定開機自啟動

   echo"/usr/local/apache/bin/apachectl start" >> /etc/rc.d/rc.local

六、安裝啟動過程排錯

1、configure:error: APR / APR-util not found.  Pleaseread the documentation.表示apr/apr-util沒有安裝,先安裝apr,再安裝apr-util,因為apr-util依賴apr,安裝apr和apr-util之前需安裝gcc工具,否則會提示configure: error: no acceptable C compiler found in $PATH.

2、configure: error: pcre-config forlibpcre not found. PCRE is required and available from http://pcre.org/,是因為pcre沒有安裝,安裝pcre之前需要先安裝gcc-c++,否則會提示configure: error: You need aC++ compiler for C++ support.

3、ServerName伺服器網域名稱

[[email protected]~]# /usr/local/apache/bin/apachectl start      

AH00558:httpd: Could not reliably determine the server‘s fully qualified domain name,using::1. Set the ‘ServerName‘ directive globally to suppress this message

[[email protected]]# cd /usr/local/apache/conf/

[[email protected]]# vi httpd.conf

在#ServerName www.example.com:80下增加一條  ServerName localhost:80

4、連接埠佔用

[[email protected]~]# /usr/local/apache/bin/apachectl start

httpd(pid 38477) already running

[[email protected]~]# ps aux | grep httpd

[[email protected]~]# kill -9 38477       //有好幾個進程,以此進行kill

[[email protected]~]# /usr/local/apache/bin/apachectl start

5、防火牆開放80連接埠或直接關閉防火牆

    如Apache後台服務已啟動,但是瀏覽器訪問不了,可能由於防火牆阻擋,兩種方式解決:

5.1開放80連接埠,推薦使用

[[email protected] ~]# iptables -I INPUT -p tcp --dport 80 -jACCEPT //開放80連接埠

[[email protected] ~]# service iptables save            //儲存策略

iptables: Saving firewall rules to/etc/sysconfig/iptables:[  OK  ]

[[email protected] ~]# service iptables status   //有下面一行證明80連接埠已開放

1    ACCEPT     tcp --  0.0.0.0/0            0.0.0.0/0           tcp dpt:80

5.2關閉防火牆,並設為防火牆開啟不啟動

[[email protected]~]# service iptables stop         //關閉防火牆

iptables:Setting chains to policy ACCEPT: filter         [  OK  ]

iptables:Flushing firewall rules:                      [  OK  ]

iptables:Unloading modules:                         [  OK  ]

[[email protected]~]# chkconfig |grep iptables      //2345為on表示開機自啟

iptables        0:off  1:off   2:on    3:on   4:on    5:on    6:off

[[email protected]~]# chkconfig iptables off      //設定iptables開機不自啟

[[email protected]~]# chkconfig |grep iptables      //2345為off為開機不自啟

iptables        0:off  1:off   2:off   3:off  4:off   5:off   6:off

             -----蔥花子 2016-12-20 

             -----轉載請註明出處 http://myitpp.blog.51cto.com  


本文出自 “蔥花子” 部落格,請務必保留此出處http://myitpp.blog.51cto.com/12252179/1884395

CentOS下安裝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.