1. 程式人生 > >Apache二進制免編譯安裝和參數配置

Apache二進制免編譯安裝和參數配置

code 參數 icons -c oba accept https 9.png main

  • 下載http相關二進制軟件包
    cd /usr/local/src/
    wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.34.tar.gz
    wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
    wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz

    說明:
    apr和apr-util是一個通用的函數庫,它讓httpd可以不關心底層的操作系統平臺,可以很方便的從linux移植到windos

  • 2.解壓安裝包

    tar zxvf  httpd-2.4.34.tar.gz
    tar zxvf apr-1.6.3.tar.gz
    tar zxvf  apr-util-1.6.1.tar.gz

    3.編譯安裝 apr-1.6.3

    cd apr-1.6.3
    ./configure --prefix=/usr/local/apr

    報錯01:

    [root@server-1 apr-1.6.3]# ./configure --prefix=/usr/local/apr
    checking build system type... x86_64-pc-linux-gnu
    checking host system type... x86_64-pc-linux-gnu
    checking target system type... x86_64-pc-linux-gnu
    Configuring APR library
    Platform: x86_64-pc-linux-gnu
    checking for working mkdir -p... yes
    APR Version: 1.6.3
    checking for chosen layout... apr
    checking for gcc... no
    checking for cc... no
    checking for cl.exe... no
    configure: error: in `/usr/local/apr-1.6.3‘:
    configure: error: no acceptable C compiler found in $PATH
    See `config.log‘ for more details
    [root@server-1 apr-1.6.3]# echo $?
    1

    解決辦法:安裝gcc

    yum install gcc -y

    再次config編譯成功

    [root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr

    技術分享圖片

    [root@server-1 apr-1.6.3]#make && make install
    [root@server-1 apr-1.6.3]# echo $?
    0

    技術分享圖片

    4.編譯安裝apr-util-1.6.1

    cd /usr/local/src/apr-util-1.6.1
    ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    make && make install

    編譯安裝報錯
    技術分享圖片
    技術分享圖片
    解決報錯:安裝expat庫

    yum install expat-devel -y

    再次執行make && make install,報錯解決
    技術分享圖片

    5.編譯安裝httpd-2.4.29

    cd /usr/local/src/httpd-2.4.29
    ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-so \   ##支持動態擴展模塊,apache支持以一個動態模塊存在,Apache本身就是一個進程服務
    --enable-mods-shared=most

    編譯報錯01:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
    技術分享圖片

    解決辦法:
    yum install pcre-devel -y

    再次執行./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most返回如下界面,表示configure編譯成功
    技術分享圖片

    註:如果在編譯過程中出現,缺少某個依賴包,解決思路
    yum list |grep 包
    然後安裝devel關鍵字的軟件包
    yum install -y 軟件包

    make && make install 編譯安裝報錯

    技術分享圖片

    說明:缺少了xml相關的庫,需要安裝libxml2-devel包。直接安裝並不能解決問題,因為httpd調用的apr-util已經安裝好了,但是apr-util並沒有libxml2-devel包支持
    解決辦法:

    參考https://blog.csdn.net/MrDing991124/article/details/78829184

    重新安裝libxml2-devel

    yum install -y libxml2-devel

    刪除apr-util軟件包

    rm -rf /usr/local/src/apr-util-1.6.1
    cd /usr/local/src/

    重新編譯安裝apr-util

    tar zxvf apr-util-1.6.1.tar.gz
    cd apr-util-1.6.1/
     ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
    make && make install

    技術分享圖片

    [root@localhost apr-util-1.6.1]# pwd
    /usr/local/src/apr-util-1.6.1
    [root@localhost apr-util-1.6.1]# cd ..
    [root@localhost src]#
    [root@localhost src]# cd httpd-2.4.34
    [root@localhost httpd-2.4.34]#
    [root@localhost httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
    返回下面界面說明configure這步編譯成功

    技術分享圖片

    make && make install
    返回下面界面說明make && make install 執行成功

    技術分享圖片

    
    root@server-1 httpd-2.4.29]# cd /usr/local/apache2.4/
    [root@server-1 apache2.4]# ls
    bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules
    說明:
    bin目錄:命令執行
    conf目錄:配置文件所在目錄
    htdocs目錄:默認網站訪問的內容就存在這個目錄下
    logs日誌目錄:訪問日誌,服務報錯日誌
    modules目錄:存放apache需要的模塊
    [root@server-1 apache2.4]# ls ./modules/

    技術分享圖片

    [root@server-1 apache2.4]# ls ./htdocs/
    index.html
    [root@server-1 apache2.4]# ls ./bin/

    技術分享圖片

    [root@server-1 apache2.4]# ls ./logs/
    [root@server-1 apache2.4]# ls ./conf/
    extra  httpd.conf  magic  mime.types  original

    查看apache服務狀態,執行/usr/local/apache2.4/bin/apachectl命令後返回如下提示

    [root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectl
    AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName‘ directive globally to suppress this message

    解決辦法:
    編譯/usr/local/apache2.4/conf/httpd.conf文件,把參數 ServerName改為

    ServerName localhost

    註意:這裏的localhost表示本機主機名,主機名可以自定義為其他
    然後重啟apache服務

    [root@localhost src]# /usr/local/apache2.4/bin/apachectl restart
    [root@localhost src]# /usr/local/apache2.4/bin/apachectl
    httpd (pid 71429) already running

    查看apache加載的模塊

    /usr/local/apache2.4/bin/httpd -M

    技術分享圖片

    說明: apache會加載兩種類型的模塊
    static:靜態模塊
    shared:動態模塊
    兩者的區別在於,static模塊是已經編譯安裝到/usr/local/apache2.4/bin/httpd配置文件中,而shared表示apache動態加載的模塊

    啟動apache服務

    /usr/local/apache2.4/bin/apachectl start

    查看apache服務進程

    [root@localhost ~]# ps aux |grep httpd
    root       1463  3.0  0.2 253600  8828 ?        Ss   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
    daemon     1464  2.0  0.2 540428  8916 ?        Sl   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
    daemon     1465  2.0  0.2 540428  8916 ?        Sl   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
    daemon     1470  1.0  0.2 540428  8912 ?        Sl   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
    root       1549  0.0  0.0 112704   972 pts/1    R+   04:19   0:00 grep --color=auto httpd
    

    Apache二進制免編譯安裝和參數配置