編譯安裝httpd 2.4

來源:互聯網
上載者:User

標籤:linux httpd


編譯安裝LAMP之:編譯安裝httpd 2.4

環境介紹:

    系統內容:CentOS6.5

所需軟體包:apr-1.5.2.tar.gz、apr-util-1.5.2.tar.gz、httpd-2.4.6.tar.gz


  注意:httpd2.4需要依賴apr和arp-util 1.4以上版本


  CentOS編譯安裝Apache準備:確保開發包組已安裝(Development tools、Server Platform Development) 

yum groupinstall "Development Tools" "Server Platform Development" -y


安裝依賴:

1、下載官方源碼包並解壓:


httpd-2.4需要較新版本的apr(1.4以上)和apr-util,因此需要事先對其進行升級。升級方式有兩種,一種是通過原始碼編譯安裝,一種是直接升級rpm包。這裡選擇使用編譯原始碼的方式進行。


wget http://archive.apache.org/dist/httpd/httpd-2.4.6.tar.bz2

wget http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz  

wget http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz


1.1 安裝apr:


    [[email protected] src]# tar xf apr-1.5.2.tar.gz 

    [[email protected] src]# cd apr-1.5.2.tar.gz

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

    [[email protected] apr-1.5.2]# make

    [[email protected] apr-1.5.2]# make install

說明:編譯時間報錯提示 rm: cannot remove `libtoolT‘: No such file or directory

     解決:直接開啟 configure,把 $RM “$cfgfile” 那行刪除掉,重新再運行 ./configure 就可以了。


1.2 安裝apr-util


    [[email protected] src]# tar xf apr-util-1.5.2.tar.gz

[[email protected] src]# cd apr-util-1.5.2

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

    [[email protected] apr-util-1.5.2]# make

    [[email protected] apr-util-1.5.2]# make install



編譯說明:


    --prefix指定安裝路徑;


    --with-apr指定apr的安裝路徑,apr-util依賴於apr


2、編譯安裝httpd

2.1 安裝依賴:


    [[email protected] src]# yum -y install pcre-devel openssl-devel


2.2 編譯安裝


    [[email protected] src]# tar xf httpd-2.4.6.tar.bz2

    [[email protected] src]# cd httpd-2.4.6

    [[email protected] httpd-2.4.6]# ./configure \

    --prefix=/usr/local/apache \

    --sysconfdir=/etc/httpd \

    --enable-so \

    --enable-rewrite \

    --enable-ssl \

    --enable-cgi \

    --enable-cgid \

    --with-zlib \

    --with-pcre \

    --enable-modules=most \

    --enable-modules-shared=most \

    --enable-mpms-shared=all \

    --with-mpm=event \

    --with-apr=/usr/local/apr \

    --with-apr-util=/usr/local/apr-util


    [[email protected] httpd-2.4.6]# make

    [[email protected] httpd-2.4.6]# make install


編譯說明:


    --prefix=/usr/local/apache :指定安裝目標路徑

    --sysconfdir=/etc/httpd :指定設定檔安裝位置

    --enable-so :支援動態共用模組,如果沒有這個模組PHP將無法與apache結合工作;DSO相容,DSO=Dynamic Shared Object,動態共用對象,可實現模組動態生效

    --enable-rewirte :支援URL重寫

    --enable-ssl :啟用支援ssl 支援SSL/TLS,可實現https訪問 需已安裝openssl-devel

    --enable-cgi :啟用支援cgi (預設情況下啟用非線程MPM)

    --enable-cgid : 啟用支援cgid (預設情況下啟用線程MPM )

--with-zlib : 支援zlib壓縮,傳輸層的壓縮(不指定具體的路徑,預設在系統中搜尋)

    --with-pcre : 支援正則化(不指定具體的路徑,預設在系統中搜尋)

    --enable-modules=most :支援動態啟用的模組,選擇性參數:all,most,few,reallyall

    --enable-mods-shared=most :安裝大多數共用模組,選擇性參數:all,most,few,reallyall (可選)

    --enable-mpms-shared=all :支援全部多道處理方式

--with-mpm :#設定預設啟用的MPM模式,{prefork|worker|event}

    --with-apr=/usr/local/apr :指定apr路徑

    --with-apr-util=/usr/local/apr-util :指定apr-util路徑


3、配置httpd 2.4(基於網域名稱的虛擬機器主機)

[[email protected] ~]# vim /etc/httpd/httpd.conf

# DocumentRoot "/usr/local/apache/htdocs"    # 注釋掉DocumentRoot關閉主服務配置段

Include /etc/httpd/extra/httpd-vhosts.conf    # 啟用虛擬機器主機功能



4、配置虛擬機器主機設定檔

[[email protected] ~]# vim /etc/httpd/extra/httpd-vhosts.conf

<VirtualHost 192.168.100.11:80>

    ServerAdmin [email protected]

    DocumentRoot "/usr/local/apache/htdocs/test1/"

    ServerName test1.parparxy.com

    ErrorLog "logs/test1-error_log"

    CustomLog "logs/test1-access_log" common

</VirtualHost>

<VirtualHost 192.168.100.11:80>

    ServerAdmin [email protected]

    DocumentRoot "/usr/local/apache/htdocs/test2/"

    ServerName test2.parparxy.com

    ErrorLog "logs/test2-error_log"

    CustomLog "logs/test2-access_log" common

</VirtualHost>



5、產生測試網頁

[[email protected] ~]# cd /usr/local/apache/htdocs/

[[email protected] htdocs]# mkdir test1 && echo "<h1> test1 </h1>" > test1/index.html

[[email protected] htdocs]# mkdir test2 && echo "<h1> test2 </h1>" > test2/index.html



6、測試指令碼檔案文法是否正確

[[email protected] ~]# ln -sv /usr/local/apache/bin/httpd /usr/bin/

`/usr/bin/httpd‘ -> `/usr/local/apache/bin/httpd‘

[[email protected] ~]# httpd -t

Syntax OK


7、為httpd執行檔案建立PATH:


    # vi /etc/profile.d/httpd.sh #添加如下一行


    export PATH=$PATH:/usr/local/apache/bin

8、啟動apache服務

[[email protected] httpd-2.4.6]# apachectl start

[[email protected] httpd-2.4.6]# netstat -tunlp | grep 80

tcp        0      0 :::80                       :::*                        LISTEN      23850/httpd         

[[email protected] httpd-2.4.6]# 



9、標頭檔輸出給系統:

# ln -sv /usr/local/apache/include /usr/local/include/httpd


10、為httpd執行檔案建立PATH:


    # vi /etc/profile.d/httpd.sh #添加如下一行


    export PATH=$PATH:/usr/local/apache/bin讓系統重建庫檔案路徑緩衝:

    # ldconfig -v |grep "^[^[:space:]]"


11、為httpd執行檔案建立PATH:


    # vi /etc/profile.d/httpd.sh #添加如下一行


    export PATH=$PATH:/usr/local/apache/bin為記錄檔建立軟串連:


    # ln -fs /usr/local/apache/logs /var/log/httpd ##設定軟連結以適應init指令碼

# apachectl start 預設的啟動apache方式


至此,就可以使用service httpd start 命令啟動httpd了。



12、配置啟動指令碼:


[[email protected] httpd-2.4.6]# cp build/rpm/httpd.init /etc/init.d/httpd //使用init指令碼管理httpd

[[email protected] httpd-2.4.6]# chmod 755 /etc/init.d/httpd //增加執行許可權

[[email protected] httpd-2.4.6]# chkconfig --add httpd //添加httpd到服務開機啟動

[[email protected] httpd-2.4.6]# ln -sf /usr/local/apache/bin/httpd /usr/sbin/httpd




問題:

Apache啟動出現:

[[email protected] httpd-2.4.6] service httpd restart

AH00557: httpd: apr_sockaddr_info_get() failed for linux.64.114

AH00558: httpd: Could not reliably determine the server‘s fully qualified domain


name, using 127.0.0.1. Set the ‘ServerName‘ directive globally to suppress this


message


解決:

[[email protected] httpd-2.4.6] vi /server/apache/conf/httpd.conf


修改ServerName www.example.com:80 為 ServerName localhost:80



初次開機服務,80連接埠未被監聽:

# cat /usr/local/apache/logs/error_log

  報錯提示:Resource Temporarily unavailable

  解決:

# ulimit -u unlimited   #修改 使用者最大進程數  

# echo ulimit -u unlimited >>/etc/profile   #儲存修改到自開機檔案  


本文出自 “眼眸刻著你的微笑” 部落格,請務必保留此出處http://dengaosky.blog.51cto.com/9215128/1852827

編譯安裝httpd 2.4

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.