centos 7中編譯安裝httpd-2.4.25.tar.gz


檢查是否已經安裝了下載工具wget和編譯環境gcc、make:
[root@jianxiangqiao ~]# rpm -qa|grep -e wget -e ^gcc -e make
gcc-4.8.3-9.el7.x86_64
make-3.82-21.el7.x86_64
wget-1.14-10.el7_0.1.x86_64
如果沒有安裝,則使用下面的命令安裝:
yum -y install wget gcc make
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package wget-1.14-10.el7_0.1.x86_64 already installed and latest version
Package gcc-4.8.3-9.el7.x86_64 already installed and latest version
Package 1:make-3.82-21.el7.x86_64 already installed and latest version
Nothing to do

安裝Apache

編譯安裝Apache組件

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兼容的正則表達式庫。

編譯安裝APR:

官方網站:http://apr.apache.org/download.cgi
最新版本:APR 1.5.2
下載地址:http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz

cd  /usr/local/src
wget  http://mirrors.hust.edu.cn/apache//apr/apr-1.5.2.tar.gz
tar  -zxf  apr-1.5.2.tar.gz
cd  apr-1.5.2
./configure  –prefix=/usr/local/apr
//–prefix=/usr/local/apr意思是指定apr的安裝目錄為/usr/local/apr
[root@jianxiangqiao apr-1.5.2]# make  &&  make install

編譯安裝APR-util:

官方網站:http://apr.apache.org/download.cgi
最新版本:APR-util 1.5.4
下載地址:http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar
# cd  /usr/local/src
# wget  http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.4.tar.gz
# tar  -zxf  apr-util-1.5.4.tar.gz
# cd  apr-util-1.5.4
# ./configure  –prefix=/usr/local/apr-util  –with-apr=/usr/local/apr
//–with-apr=/usr/local/apr選項的意思是指定apr的安裝位置/usr/local/apr
# make  &&  make install

編譯安裝PCRE:

官方網站:http://pcre.org/
最新版本:pcre-8.37,不能使用PCRE2
下載地址:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz

# cd /usr/local/src
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz
# tar -zxf pcre-8.37.tar.gz
# cd pcre-8.37
# ./configure –prefix=/usr/local/pcre
# make  &&  make  install

編譯安裝Apache

官方網站:http://httpd.apache.org/
最新版本:Apache httpd 2.4.17 Released(2015-10-13)
下載地址:http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.17.tar.gz
# cd  /usr/local/src
# wget  http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.17.tar.gz
# tar  -zxf  httpd-2.4.17.tar.gz 
# cd httpd-2.4.17
# ./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
# make  &&  make  install

配置Apache

配置防火牆

# firewall-cmd –permanent –add-service=http
success
# firewall-cmd –reload
success

配置SELinux

# semanage fcontext -a -t httpd_sys_content_t ‘/usr/local/apache/htdocs(/.*)?’
# restorecon -RFvv /usr/local/apache/htdocs
restorecon reset /usr/local/apache/htdocs context system_u:object_r:usr_t:s0->system_u:object_r:httpd_sys_content_t:s0
restorecon reset /usr/local/apache/htdocs/index.html context system_u:object_r:usr_t:s0->system_u:object_r:httpd_sys_content_t:s0

啟動Apache

啟動和停止Apache
使用httpd命令控制Apache,執行以下命令:
# /usr/local/apache/bin/httpd -k start
# /usr/local/apache/bin/httpd -k stop

使用腳本控制Apache,執行以下命令:
# /usr/local/apache/bin/apachectl start
# /usr/local/apache/bin/apachectl stop

設置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參數將其添加進去
# chkconfig –add httpd
# chkconfig –list httpd
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use ‘systemctl list-unit-files’.
To see services enabled on particular target use
‘systemctl list-dependencies [target]’.
httpd 0:off 1:off 2:off 3:on 4:off 5:on 6:off


免責聲明!

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



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