[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:
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:
# 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:
# 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
最新版本:Apache httpd 2.4.17 Released(2015-10-13)
下載地址:http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.17.tar.gz
# 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
# 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,第二、三是關於啟動和停止的優先級配置,無關緊要。
# 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