Centos6.8 編譯安裝Apache2.4


cetos6.8源碼安裝apache2.4.29

apache官網: http://httpd.apache.org

具體安裝步驟:

1 配置安裝apache的基礎環境
2 下載想要安裝的版本源碼包
3 解壓,預編譯,編譯,安裝
4 啟動,停止,測試頁面,檢驗是否安裝成功
5 編寫啟動腳本,將apache添加為系統服務,設置為開機啟動

=================================================================== 

1 配置安裝環境:

yum -y install gcc gcc++ zlib zlib-devel 

卸載原有的Apache
rpm -qa|grep httpd
刪除已經安裝的所有httpd包
rpm -e --nodeps httpd-xxx-xxx.el6.xxx.x86_64

2 下載對應版本的包
wget http://mirrors.shuosc.org/apache//httpd/httpd-2.4.29.tar.gz


1)去http://httpd.apache.org/download 下載apache源碼包

2)解壓到/usr/src,在下載目錄執行tar -zxvf httpd-x.x.x.tar.gz -C /usr/src (我用的是httpd-2.4.29.tar.gz)

3)進入目錄/usr/src/httpd-2.4.29,

 # ./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl

4)出現configure: error: APR not found。解決辦法:

  4.1)去apr下載地址 http://apr.apache.org/ 下載源碼
  wget http://mirrors.shuosc.org/apache//apr/apr-1.6.3.tar.gz
  http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

  4.2)解壓到/usr/src,在下載目錄執行tar -zxvf apr-x.x.x.tar.gz -C /usr/src/ (我用的是apr- 1.6.3.tar.gz)

  4.3)進入目錄/usr/src/apr-1.6.3,執行./configure --prefix=/usr/local/apr;make;make install

5)再次進入目錄/usr/src/httpd-2.4.29,增加參數--with-apr=/usr/local/apr/

重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/

6)出現configure: error: APR-util not found .解決辦法

  6.1)去apr-util下載地址 http://apr.apache.org/ 下載源碼
  wget http://mirrors.shuosc.org/apache//apr/apr-util-1.6.1.tar.gz
  http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz

  6.2)解壓到/usr/src,在下載目錄執行tar -zxvf apr-util-x.x.x.tar.gz -C /usr/src/ (我用的是apr-util-1.6.1.tar.gz)

  6.3)進入目錄/usr/src/apr-util-1.6.1,執行./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/;make;make install

  6.4)make的時候出現錯誤
xml/apr_xml.c:35:19: error: expat.h: No such file or directory
xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: In function ‘cleanup_parser’:
xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:365: error: ‘apr_xml_parser’ has no member named ‘xp’
  解決辦法:可能是缺少expat庫
    6.4.1)yum install expat-devel 安裝之后再make;make install

7)再次進入目錄/usr/src/httpd-2.4.29,增加參數--with-apr-util=/usr/local/apr-util/,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/

8)出現configure: error: pcre-config for libpcre not found.解決辦法:

  8.1)去pcre下載地址 http://pcre.org/ 下載源碼(注意:下載的時候一定不要下錯了,不是pcre2 )
  wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

  8.2)解壓到/usr/src,在下載目錄執行tar -zxvf pcre-x.x.tar.gz -C /usr/src/ (我用的是pcre-8.40.tar.gz)

  8.3)進入目錄/usr/src/pcre-8.31,執行./configure --prefix=/usr/local/pcre;make;make install

 

9)再次進入目錄/usr/src/httpd-2.4.29,增加參數--with-pcre=/usr/local/pcre,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre

10)出現configure: WARNING: OpenSSL version is too old;checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures;解決辦法:

  10.1)openssl源碼下載地址http://www.openssl.org/source/ 下載源碼
  wget https://www.openssl.org/source/openssl-1.0.2n.tar.gz

  10.2)解壓到/usr/src,在下載目錄執行tar -zxvf openssl-x.x.x.tar.gz -C /usr/src/ (我用的是openssl-1.0.2n.tar.gz)

  10.3)進入目錄/usr/src/openssl-1.0.1c,執行./config --prefix=/usr/local/openssl shared;make;make install

 注意此處的shared選項,否則在httpd make的時候會報mod_ssl相關錯誤

 

11)再次進入目錄/usr/src/httpd-2.4.3,增加參數--with-ssl=/usr/local/openssl,重新執行:./configure --prefix=/usr/local/apache2 --with-mpm=worker --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-nonportable-atomics --enable-mods-shared=most --enable-so --enable-rewrite --enable-ssl --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-ssl=/usr/local/openssl ;預編譯沒有問題


make出現以下錯誤:
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode'
/usr/local/apr-util/lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler
collect2: error: ld returned 1 exit status
make[2]: *** [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/httpd-2.4.26/support'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/httpd-2.4.26/support'
make: *** [all-recursive] Error 1

解決辦法發:centos6.8的系統使用1.6的apr 和apr-util版本太高了,需要降低版本,將apr和apr-util降為1.5的版本,在重新編譯安裝即可。下載地址如下:
http://archive.apache.org/dist/apr/apr-util-1.5.2.tar.gz
http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz

 


12)設置apache開機自動啟動

首先拷貝apachectl到目錄/etc/init.d/,執行命令sudo cp apachectl /etc/init.d/httpd
vim /etc/init.d/httpd 腳本首行添加以下兩行
# chkconfig: 2345 71 71
# description: Apache2.4 is a world wide web server
注意:2345 是指改服務可以隨系統的2345啟動級別啟動和停止,71 71 兩個數字分別指啟動順序和停止順序。
13)將httpd添加為開機啟動
chkconfig --add httpd
這行命令的意思是在/etc/rc.d/rc*/ 添加/etc/init.d/httpd這個文件
chkconfig --list |grep httpd 查看是否將httpd添加為系統服務
chkconfig httpd on 開啟開機啟動httpd服務

14)去瀏覽器輸入127.0.0.1,可以顯示apache自帶的網頁It works。該網頁的默認目錄是在/usr/local/apache2/htdocs/。apache到此就安裝OK了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM