centos7下源碼編譯方式安裝httpd

來源:互聯網
上載者:User

標籤:bsp   div   目的   不同   針對   細節   r檔案   stop   apr-util   

文法:chkconfig --list [name]chkconfig --add namechkconfig --del namechkconfig [--level levels] name <on|off|reset>chkconfig [--level levels] name

參考文章http://www.cnblogs.com/jipeng87/p/6308725.html

前言

Apache至少需要apr、apr-util、pcre組件的支援。
APR(Apache portable Run-time libraries,Apache可移植運行庫)的目的如其名稱一樣,主要為上層的應用程式提供一個可以跨越多作業系統平台使用的底層支援介面庫。在早期的Apache版本中,應用程式本身必須能夠處理各種具體作業系統平台的細節,並針對不同的平台叫用不同的處理函數。隨著Apache的進一步開發,Apache組織決定將這些通用的函數獨立出來並發展成為一個新的項目。這樣,APR的開發就從Apache中獨立出來,Apache僅僅是使用APR而已。目前APR主要還是由Apache使用,不過由於APR的較好的移植性,因此一些需要進行移植的C程式也開始使用APR。
APR-util是在APR的基礎上提供了更多的資料結構和作業系統封裝介面。APR-util依賴於APR,必須先安裝APR再安裝APR-util。
PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括perl相容的Regex庫。

源碼的安裝一般由3個步驟組成:配置(configure)、編譯(make)、安裝(make install)

1.查詢是否安裝了apache伺服器httpd

[[email protected] src]# rpm -qa|grep httpd
httpd-2.4.6-45.el7.centos.x86_64
httpd-tools-2.4.6-45.el7.centos.x86_64
2.卸載系統自動裝的apache伺服器httpd

[[email protected] src]# httpd -k stop     #停止httpd伺服器

[root[email protected] src]# yum remove httpd    #卸載httpd伺服器

4 下載httpd-2.4.25   apr-1.5.2  apr-util-1.5.4  pcre-8.40

[[email protected] src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.25.tar.gz
[[email protected] src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.5.2.tar.gz
[[email protected] src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.5.4.tar.gz

[[email protected] src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
5 檢查系統是否安裝了GCC

[[email protected] src]# gcc
bash: gcc: 未找到命令...      #出現未找到命令提示,說明沒有安裝GCC
6 安裝GCC和gcc-c++

[[email protected] src]# yum -y install gcc

[[email protected] pcre-8.40]# yum -y install gcc-c++

注意:如果沒有安裝gcc-c++,那麼在 執行./configure  -prefix=/usr/local/pcre 時會報 configure: error: You need a C++ compiler for C++ support. 錯誤

7 將下載的壓縮檔拷貝到/usr/local目錄下

[[email protected] src]# cp apr-1.5.2.tar.gz /usr/local
[[email protected] src]# cp apr-uril-1.5.4.tar.gz /usr/local

[[email protected] src]# cp httpd-2.4.25.tar.gz  /usr/local

8 編譯安裝apr-1.5.2

#解壓縮apr檔案

[[email protected] local]# tar -zxvf apr-1.5.2.tar.gz                          

#改變目錄到apr-1.5.2

[[email protected] local]# cd apr-1.5.2

#指定apr的安裝目錄為/usr/local/apr 配置

[[email protected] apr-1.5.2]# ./configure -prefix=/usr/local/apr

#編譯安裝
[[email protected] apr-1.5.2]# make && make install

9 編譯安裝 apr-uril-1.5.4

#解壓縮apr-util檔案

[[email protected] local]# tar -zxvf apr-util-1.5.4.tar.gz

#改變目錄到apr-util-1.5.4/

[[email protected] local]# cd apr-util-1.5.4/

#指定apr-util的安裝路徑,指定apr-util所對應的apr
[[email protected] apr-util-1.5.4]# ./configure  -prefix=/usr/local/apr-util  -with-apr=/usr/local/apr

#編譯安裝
[[email protected] apr-util-1.5.4]# make && make install
10 編譯安裝pcre

#卸載系統內建的pcre

[[email protected] apr-util-1.5.4]# rpm -qa pcre
pcre-8.32-15.el7_2.1.x86_64

#解壓縮apr-util檔案

[[email protected] local]# tar -zxvf pcre-8.40.tar.gz
#改變目錄到pcre-8.40/

[[email protected] local]# cd pcre-8.40/

#指定prce的安裝路徑,指定apr-util所對應的apr
[[email protected] pcre-8.40]# ./configure  -prefix=/usr/local/pcre

#編譯安裝(make是編譯 make install是安裝)
[[email protected] pcre-8.40]# make && make install

11 編譯安裝apache

編譯和安裝apache分為動態、靜態兩種方式。動態編譯是指在以後的使用中隨時調整設定檔就可以載入模組;靜態則相反,在編譯時間就決定了相應的模組。

#解壓縮httpd-2.4.25檔案

[[email protected] local]# tar -zxvf httpd-2.4.25.tar.gz

#改變目錄到httpd-2.4.25/
[[email protected] local]# cd httpd-2.4.25/

#配置
[[email protected] httpd-2.4.25]# ./configure -prefix=/usr/local/apache -sysconfdir=/etc/httpd -enable-so -enable-rewrite -with-apr=/usr/local/apr -with-apr-util=/usr/local/apr-util -with-pcre=/usr/local/pcre
#編譯安裝

[[email protected] httpd-2.4.25]#make && make install

12配置apache防火槍

#永久開放http服務

[[email protected] httpd-2.4.25]# firewall-cmd --permanent --add-service=http
success
#重新載入防火牆

[[email protected] httpd-2.4.25]# firewall-cmd --reload
success

12 啟動,停止apache服務

#編輯httpd.conf檔案

[[email protected] httpd-2.4.25]#vi /etc/httpd/httpd.conf

 在#ServerName www.example.com:80 下增加下面的語句
 ServerName localhost:80

#使用指令碼控制Apache,啟動服務

[[email protected] ~]#  /usr/local/apache/bin/apachectl start

#使用指令碼控制Apache,停止服務

[[email protected] ~]#  /usr/local/apache/bin/apachectl stop

#服務啟動後,在瀏覽器輸入http://localhost瀏覽器內容顯示出it works

13 設定apache開機啟動

1、將apachectl命令拷貝到/etc/init.d目錄下,改名為httpd
# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

2、編輯/etc/init.d/httpd檔案,在第1行#!/bin/sh的後面添加如下兩行
# vi /etc/init.d/httpd
# chkconfig: 2345 70 30
# description: Apache

其中,所增加的第二行中三個數字,第一個表示在運行層級2345下啟動Apache,第二、三是關於啟動和停止的優先順序配置。

3、Apache服務尚未被添加到chkconfig列表中,需要使用–add參數將其添加進去
[[email protected] init.d]# chkconfig --add httpd
[[email protected] init.d]# chkconfig --list httpd

通過上面的設定,每次開機時apache服務都是自動啟動的

注意:該輸出結果只顯示 SysV 服務,並不包含原生 systemd 服務。SysV 配置資料可能被原生 systemd 配置覆蓋。
      如果您想列出 systemd 服務,請執行 ‘systemctl list-unit-files‘。
      欲查看對特定 target 啟用的服務請執行
      ‘systemctl list-dependencies [target]‘。

httpd              0:關    1:關    2:開    3:開    4:開    5:開    6:關

註:chkconfg是檢查,設定系統的各種服務。
chkconfg文法如下:

chkconfig --list [name]

chkconfig --add namechkconfig --del namechkconfig [--level levels] name <on|off|reset>chkconfig [--level levels] name

centos7下源碼編譯方式安裝httpd

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.