編譯安裝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:
[root@Server src]# tar xf apr-1.5.2.tar.gz
[root@Server src]# cd apr-1.5.2.tar.gz
[root@Server apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@Server apr-1.5.2]# make
[root@Server apr-1.5.2]# make install
說明:編譯時報錯提示 rm: cannot remove `libtoolT': No such file or directory
解決:直接打開 configure,把 $RM “$cfgfile” 那行删除掉,重新再運作 ./configure 就可以了。
1.2 安裝apr-util
[root@Server src]# tar xf apr-util-1.5.2.tar.gz
[root@Server src]# cd apr-util-1.5.2
[root@Server apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@Server apr-util-1.5.2]# make
[root@Server apr-util-1.5.2]# make install
編譯說明:
--prefix指定安裝路徑;
--with-apr指定apr的安裝路徑,apr-util依賴于apr
2、編譯安裝httpd
2.1 安裝依賴:
[root@Server src]# yum -y install pcre-devel openssl-devel
2.2 編譯安裝
[root@Server src]# tar xf httpd-2.4.6.tar.bz2
[root@Server src]# cd httpd-2.4.6
[root@Server 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
[root@Server httpd-2.4.6]# make
[root@Server 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(基于域名的虛拟主機)
[root@Server ~]# vim /etc/httpd/httpd.conf
# DocumentRoot "/usr/local/apache/htdocs" # 注釋掉DocumentRoot關閉主服務配置段
Include /etc/httpd/extra/httpd-vhosts.conf # 啟用虛拟主機功能
4、配置虛拟主機配置檔案
[root@Server ~]# 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>
DocumentRoot "/usr/local/apache/htdocs/test2/"
ServerName test2.parparxy.com
ErrorLog "logs/test2-error_log"
CustomLog "logs/test2-access_log" common
5、生成測試網頁
[root@Server ~]# cd /usr/local/apache/htdocs/
[root@Server htdocs]# mkdir test1 && echo "<h1> test1 </h1>" > test1/index.html
[root@Server htdocs]# mkdir test2 && echo "<h1> test2 </h1>" > test2/index.html
6、測試腳本檔案文法是否正确
[root@Server ~]# ln -sv /usr/local/apache/bin/httpd /usr/bin/
`/usr/bin/httpd' -> `/usr/local/apache/bin/httpd'
[root@Server ~]# httpd -t
Syntax OK
7、為httpd執行檔案建立PATH:
# vi /etc/profile.d/httpd.sh #添加如下一行
export PATH=$PATH:/usr/local/apache/bin
8、啟動apache服務
[root@Server httpd-2.4.6]# apachectl start
[root@Server httpd-2.4.6]# netstat -tunlp | grep 80
tcp 0 0 :::80 :::* LISTEN 23850/httpd
[root@Server httpd-2.4.6]#
9、頭檔案輸出給系統:
# ln -sv /usr/local/apache/include /usr/local/include/httpd
10、為httpd執行檔案建立PATH:
export PATH=$PATH:/usr/local/apache/bin讓系統重新生成庫檔案路徑緩存:
# ldconfig -v |grep "^[^[:space:]]"
11、為httpd執行檔案建立PATH:
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、配置啟動腳本:
[root@Server httpd-2.4.6]# cp build/rpm/httpd.init /etc/init.d/httpd //使用init腳本管理httpd
[root@Server httpd-2.4.6]# chmod 755 /etc/init.d/httpd //增加執行權限
[root@Server httpd-2.4.6]# chkconfig --add httpd //添加httpd到服務開機啟動
[root@Server httpd-2.4.6]# ln -sf /usr/local/apache/bin/httpd /usr/sbin/httpd
問題:
Apache啟動出現:
[root@Server 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
解決:
[root@Server 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 #儲存修改到自啟動檔案
本文轉自 dengaosky 51CTO部落格,原文連結:http://blog.51cto.com/dengaosky/1852827,如需轉載請自行聯系原作者