一、安装前的准备
需要安装gcc、g++编译环境,详见《CentOS7.5安装gcc、g++》。
二、编译安装Apache httpd2.4之前,需要预先安装apr、apr-util、pcre
1. 下载apr、 apr-util
(1)官方网址:http://apr.apache.org/
(2)返回用户主目录,将安装包下载到用户主目录下
cd ~
(3)下载tar包
wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.6.3.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
2. 下载pcre
(1)网址:http://www.pcre.org/
(2)返回用户主目录,将安装包下载到用户主目录下
cd ~
(3)下载tar包
wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz
(4)特别说明
安装httpd2.4.33时不能使用pcre2包(pcre2-10.31.tar.gz),否则会报错:
checking for pcre-config... false
configure: error: Did not find pcre-config script at /usr/local/pcre
3. 解压tar.gz
tar -zxvf apr-1.6.3.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
tar -zxvf pcre-8.42.tar.gz
三、安装apr、apr-util、pcre
1. 安装apr
cd ~/apr-1.6.3
./configure --prefix=/usr/local/apr
make
make install
2. 安装apr-util
cd ~/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
***出现错误提示:
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
#include <expat.h>
***原因:
缺少expat-devel包
***执行以下操作:
yum install expat-devel
***继续操作:
make
make install
3. 安装pcre
cd ~/pcre-8.42/
./configure --prefix=/usr/local/pcre
make
make install
四、安装httpd
1. 官方网址:http://httpd.apache.org/
2. 返回用户主目录,将安装包下载到用户主目录中
cd ~
3. 下载tar包
wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.33.tar.gz
4. 切换当前目录
cd ~/httpd-2.4.33/
5. 执行命令:
./configure --prefix=/usr/local/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-zlib --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
***出现错误提示:
configure: WARNING: OpenSSL version is too old
no
checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
***原因:
缺少openssl、openssl-devel包
***执行以下操作:
yum install openssl
yum install openssl-devel
6. 继续执行2中configure命令
7. 执行命令
make
make install
8. 启动、重启、停止apache服务
/usr/local/httpd/bin/apachectl -k start
/usr/local/httpd/bin/apachectl -k restart
/usr/local/httpd/bin/apachectl -k stop
9. 安装成功!可以在浏览器中打开地址测试
五、参考文献
Apache HTTP Server Project Documentation Version 2.4:Compiling and Installing