一、下載軟件包 (wget)
通過 https://apr.apache.org/ 下載 APR 和 APR-util //此網址不是直接的目標地址
通過 http://httpd.apache.org/download.cgi 下載 httpd //此網址不是直接的目標地址
通過 https://ftp.pcre.org/pub/pcre/ 下載 pcre //此網址不是直接的目標地址
二、配置安裝環境
yum -y install gcc gcc-c++ make expat-devel
三、解壓與編譯安裝
mkdir /data
(1)編譯安裝 APR
tar xf apr-1.7.0.tar.gz -C /data
cd /data
mv apr-1.7.0/ apr
cd apr/
./configure --prefix=/data/apr && make && make install
(2)編譯安裝 APR-util
tar xf apr-util-1.6.1.tar.gz -C /data
cd /data
mv apr-util-1.6.1/ apr-util
cd apr-util/
./configure --prefix=/data/apr-util --with-apr=/data/apr && make && make install
(3)編譯安裝 pcre
tar xf pcre-8.43.tar.gz -C /data
cd /data
mv pcre-8.43/ pcre
cd pcre/
./configure --prefix=/data/pcre && make && make install
(4)編譯安裝 httpd
tar xf httpd-2.4.41.tar.gz -C /data
cd /data
mv httpd-2.4.41/ apache
cd apache/
./configure --prefix=/data/apache --with-apr=/data/apr --with-apr-util=/data/apr-util && make && make install
四、啟動與關閉
/data/apache/bin/apachectl start //啟動
/data/apache/bin/apachectl stop //關閉
開放80端口
firewall-cmd --permanent --and-port=80/tcp
firewall-cmd -reload
配置開機自啟
(1)將 apachectl 命令拷貝到 /etc/init.d 目錄下,改名為httpd
cp /data/apache/bin/apachectl /etc/init.d/httpd
(2)編輯 /etc/init.d/httpd 文件,在第一行 #!/bin/bash 的后面添加如下兩行
chkconfig: 2345 70 40
說明:2345 表示腳本運行的級別,即在2、3、4、5這4種模式下都可以運行,70 表示腳本啟動的順序號,40 表示系統關閉時,腳本的停止順序號
description:apache
(3)將 Apache 服務加入到系統服務
chkconfig --add httpd
chkconfig --list httpd
(4)通過使用 systemctl 命令控制 Apache 的啟動和停止
啟動 Apache 服務
systemctl start httpd.service
查看 Apache 服務運行狀態
systemctl status httpd.service
關閉 Apache 服務
systemctl stop httpd.service
五、安裝中遇到的問題以及解決辦法
錯誤:configure:error:no acceptable C compiler found in $PATH
解決:需要安裝 gcc
錯誤:rm:cannot remove ‘libtoolT’:No such file or directory
解決:編輯 /data/apr/configure , 找到 $RM '$cfgfile' 進行注釋
錯誤:configure:error:APR not found. Please read the documentation.
解決:需要安裝 APR 和 APR-util
錯誤:xml/apr_xml.c:35:19: 致命錯誤:expat.h:沒有那個文件或目錄
解決:需要安裝 expat-devel 包
錯誤:configure:error:pcre-config for libpcre not found. PCRE is required and availab le from
解決:需要安裝 pcre
錯誤:如果報多個 .so:undefined reference to 'XXX'
解決:有可能是下載的 APR-util 包 有問題。換一個下載就好了。