編譯安裝Apache
系統環境:centos 7.2
前提:
提供開發工具及開發環境
-
開發工具:make, gcc等
-
開發環境:開發庫,頭文件
-
glibc:標準庫
方式:
通過“包組”提供開發組件
centos 6 [root@centos6 ~]# yum groupinstall "Development Tools" [root@centos6 ~]# yum groupinstall "Development tools" centos 7 [root@centos6 ~]# yum groupinstall "Development Tools"
1、首先在方法網站http://www.apache.org/下載源碼包
下載路徑:http://apache.fayea.com/httpd/httpd-2.2.31.tar.gz
2、我們將下載好的文件放置在/root目錄下
3、我們可以看到源碼包的格式為.tar.gz 所有這里我們要將源碼包進行解壓縮和拆包
[root@centos7 ~]# tar xvzf httpd-2.2.31.tar.gz
4、執行完上述操作后,在當前目錄即(/root)目錄下,我們可以看到httpd-2.2.31目錄,進入該目錄
[root@centos7 ~]# cd httpd-2.2.31/
5、在該目錄下,有眾多的文件,我們首先關注的是 README 文件和 INSTALL 文件
README 文件主要簡單的介紹了 [root@centos7 httpd-2.2.31]# less README what is it? The latest version documentation installation licensing Cryptographic Software Notice Contacts Acknowledgments 通過以上的說明可以使我們對Apache有一個簡單的了解 INSTALL 文件主要說明了安裝的方法 [root@centos7 httpd-2.2.31]# less INSTALL $ ./configure --prefix=PREFIX $ make $ make install $ PREFIX/bin/apachectl start
6、通過查看以上文件,下面我們可以進行Apache的編譯安裝
首先我們來介紹下configure腳本的參數說明
[root@centos7 httpd-2.2.31]# ./configure --help Installation directories:指定默認的安裝位置 --prefix=PREFIX install architecture-independent files in PREFIX [/usr/local/apache2] Fine tuning of the installation directories:默認文件安裝位置 --bindir=DIR user executables [EPREFIX/bin] --sbindir=DIR system admin executables [EPREFIX/sbin] --sysconfdir=DIR read-only single-machine data [PREFIX/etc] ...... ...... System types:交叉編譯選項 --build=BUILD configure for building on BUILD [guessed] --host=HOST cross-compile to build programs to run on HOST [BUILD] --target=TARGET configure for building compilers for TARGET [HOST] Optional Features:可選特性 --disable-option-checking ignore unrecognized --enable/--with options --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-v4-mapped Allow IPv6 sockets to handle IPv4 connections ...... ...... Optional Packages:可選包 --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) --with-included-apr Use bundled copies of APR/APR-Util
6(1)這里我們指定幾個簡單的選項即可:
[root@centos7 httpd-2.2.31]# ./configure --prefix=/usr/local/http2 --sysconfdir=/etc/http2 //該步驟執行完畢后,會結合 Makefile.in 文件,在當前目錄下生成 Makefile 文件 //出現error等信息,說明配置失敗
6(2)執行make和make install命令(上一步執行成功后) 注意:要始終處于當前目錄下,不要離開該目錄
[root@centos7 httpd-2.2.31]# make [root@centos7 httpd-2.2.31]# make install
7、啟動
[root@centos7 httpd-2.2.31]# cd /usr/local/http2/bin [root@centos7 bin]# ./apachectl start [root@centos7 bin]# netstat -tapn | grep "80" tcp6 0 0 :::80 :::* LISTEN 14611/http
8、測試
centos 6.8系統下測試
[root@centos6 ~]# links 10.1.249.146 //10.1.249.146 為以上編譯安裝Apache軟件的centos 7系統 的IP
在Windows系統下測試
任意一款瀏覽器下輸入:http://10.1.249.146/
注意:如果啟動成功但是卻始終訪問不了,則可能的原因是centos 7 的防火墻沒有關閉,所以建議關閉防火墻后在做測試
[root@centos7 ~]# iptables -F
9、最后的配置
我們知道一個程序主要由4類文件組成
-
二進制文件
-
配置文件
-
庫文件
-
幫助文檔
[root@centos7 ~]# cd /usr/local/http2/ [root@centos7 http2]# ls bin build cgi-bin error htdocs icons include lib logs man manual modules
以上4類文件應該放置在系統特定的目錄下 或者通過修改系統相關的配置文件
(1)二進制文件 bin目錄 添加其路徑到PATH環境變量即可
[root@centos7 http2]# vim /etc/profile.d/http.sh export PATH=/usr/local/http2/bin:$PATH [root@centos7 http2]# echo $PATH /usr/local/http2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
(2)配置文件我們在編譯安裝時已經通過 –sysconfdir=/etc/http2 選項指定了
(3)庫文件 lib目錄
[root@sixijie http2]# vim /etc/ld.so.conf.d/http2.conf /usr/local/http2/lib
讓系統重新生成庫文件路徑緩存
[root@sixijie apache2]# ldconfig -v 緩存文件:/etc/ld.so.cache
(4)幫助文檔 man
[root@centos7 lib]# vim /etc/man_db.conf (centos 7) 添加一行內容:MANDATORY_MANPATH /usr/local/http2/man
(5)對于 include 頭文件 采用軟鏈接的方式(/usr/include為系統頭文件位置)
[root@centos7 include]# ln -s /usr/local/http2/include/ /usr/include/http [root@centos7 include]# ll -d /usr/include/http lrwxrwxrwx. 1 root root 25 Aug 23 20:46 /usr/include/http -> /usr/local/http2/include/ [root@centos7 include]# ll /usr/include/http/
至此安裝配置完成
原創文章,作者:sixijie,如若轉載,請注明出處:http://www.www58058.com/39877