準備工作(/usr/local/src/目錄下)
1.下載httpd源碼包,解壓
$ wget http://apache.fayea.com//httpd/httpd-2.4.25.tar.bz2
$ tar jxf httpd-2.4.25.tar.bz2
2.下載apr和apr-util源碼包,解壓,改名,移至/httpd/解壓目錄/路徑/src/lib/
$ wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.gz
$ wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
$ tar zxf apr-1.5.2.tar.gz
$ tar zxf apr-util-1.5.4.tar.gz
$ mv apr-1.5.2 apr ; mv apr-util-1.5.4 apr-util
$ mv apr apr-util httpd-2.4.25/srclib/
3.編譯安裝pcre
$ wget https://ncu.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.bz2
$ tar jxf pcre-8.39.tar.bz2
$ cd pcre-8.39
$ ./configure --prefix=/usr/local/pcre
$ make && make install
$ echo $?
4.yum安裝GCC編譯器、OpenSSL(支持ssl模塊)、Perl(支持apxs工具)
$ yum install gcc openssl openssl-devel perl perl-devel -y
安裝過程(/usr/local/src/httpd-2.4.25/目錄下)
1.配置參數
$ ./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre \
--with-ssl
注:
--prefix=/usr/local/apache2
指定安裝路徑
--with-included-apr
Apache portable Run-time libraries,Apache可移植運行庫
--enable-s
激活apache的dso模塊的支持,以後可以用DSO方式編譯安裝共享模塊。
--enable-deflate=shared
提供對內容的壓縮傳輸編碼,shared表示動態加載,需要時再加載模塊。
--enable-expires=shared
允許通過配置文件控制http的"Expires"和 "Cache-Control"頭內容,對圖片,css,js等內容配置客戶端瀏覽器緩存。
--enable-rewrite=shared
提供基於url 規則的重寫功能
--with-pcre
perl兼容正則表達式庫
--with-ssl
支持ssl
2.編譯和安裝
$ make && make install
3.啓動apache
$ /usr/local/apache2/bin/apachectl start
若出現錯誤如下:
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.ding for ServerName1)
通過編輯httpd.conf解決:
$ vim /usr/local/apache/conf/httpd.conf
/ServerName 查找行
#ServerName www.example.com:80
ServerName 自定義主機名:80 添加行
$ /usr/local/apache/bin/apachectl restart
/usr/local/apache2/bin/apachectl選項
1) -M
列出模塊,模塊目錄爲/usr/local/apache2/modules/,*.so表示動態模塊。
2) –l
列出靜態模塊,其中event.c爲默認MPM(Multi-Processing Modules,多路處理模塊)。等同於/usr/local/src/apache-2.4.25/目錄下運行#./httpd -l。
3) –t
檢查配置文件是否有語法錯誤,配置文件爲/usr/local/apache2/conf/httpd.conf。
4) /usr/local/apache2/bin/apachectl stop
結束httpd服務進程,結束後可以用start、restart和graceful重啓服務。
錯誤之處,還望指出,多謝!