源碼編譯安裝Apache

編譯安裝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

源碼編譯安裝Apache

在Windows系統下測試

任意一款瀏覽器下輸入:http://10.1.249.146/

源碼編譯安裝Apache

注意:如果啟動成功但是卻始終訪問不了,則可能的原因是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

(0)
sixijiesixijie
上一篇 2016-08-24 21:21
下一篇 2016-08-24 21:21

相關推薦

  • lvs-dr

            通過為請求報文重新封裝一個MAC首部進行轉發,源MAC是DIP所在的接口的MAC,目標MAC是某挑選出的RS的RIP所在接口的MAC地址;源IP/PORT,以及目標IP/PORT均保持不變;     VIP通常配置在lo:0…

    2017-06-29
  • Ansible Playbook Roles 和 Include 聲明-手稿

    Edit Ansible Playbook Roles 和 Include 聲明 Ansible Playbook Roles 和 Include 聲明 1. Introduction 2. Task Include Files And Encouraging Reuse 3. Roles 4. Role Default Variables 5. Role …

    Linux干貨 2016-03-28
  • httpd功能配置之CGI程序

        httpd服務中有一個cgi-bin目錄,此目錄專門用于存放cgi腳本。CGI即網關通用接口,用于實現動態網頁。下面簡單編寫一個CGI腳本來進行測試此功能:     1、在/var/www/cgi-bin/目錄下創建一個腳本     2、重啟服務     3、驗證 &nb…

    Linux干貨 2016-03-11
  • linux的tty

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://jeffyyko.blog.51cto.com/28563/140012 最近做了一個小測試,得到了以下結論 測試linux發行版本:rhel AS4.0 環境:VMware 5.0 目的:修改 vi /etc/initt…

    Linux干貨 2015-03-26
  • 網卡別名及多網卡配置

    網卡別名 對于要在不同網段環境中使用的設備有很大的幫助。     要使用網卡別名首先要關閉NetworkManager這個服務,防止在后續操作中引起不必要的沖突。 [root@laodeng6 ~]# chkconfig NetworkManager off [root@laod…

    Linux干貨 2016-09-06
  • linux入門

    基本知識和操作用法。

    Linux干貨 2017-11-30
欧美性久久久久