centos 7手动编译部署Apache

本文主要用于记录在CentOS 7上手动编译并部署apache.

下载apache

  1. 下载apache
1
curl -O http://mirror.cc.columbia.edu/pub/software/apache//httpd/httpd-2.4.43.tar.gz
  1. 下载依赖
1
2
3
4
# apr
curl -O http://mirror.cc.columbia.edu/pub/software/apache//apr/apr-1.7.0.tar.gz
# apr util
curl -O http://mirror.cc.columbia.edu/pub/software/apache//apr/apr-util-1.6.1.tar.gz
  1. 解压安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#解压安装
tar -zxvf ./httpd-2.4.43.tar.gz
tar -zxvf ./apr-1.7.0.tar.gz
tar -zxvf ./apr-util-1.6.1.tar.gz
#编译安装apr
cd ./apr-1.7.0/
./configure --prefix=/usr/local/apr
make
make install
#编译安装apr-util
cd ./apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make
make install

在编译解决办法如下:apr-util时,会报错:

1
2
3
4
5
6
7
8
9
xml
/apr_xml.c:35:19:
fatal error: expat.h: No such file or directory
#include <expat.h>
^
compilation terminated.
make[1]: *** [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/data/jumper-cs/downloads/apr-util-1.6.1'
make: *** [all-recursive] Error 1

解决办法如下:

1
yum install -y expat-devel

然后重新编译安装apr-util。最后编译apache:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 如果没有安装pcre,先按照pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.43.tar.gz
tar -zxvf pcre-8.43.tar.gz
cd pcre-8.43
./configure --prefix=/usr/local/pcre
make
make install
# 开始安装apache...
cd httpd-2.4.43/
./configure --prefix=/apache24 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
make
make install

# 最后启动apache,注意:启动之前请修改端口
/apache24/bin/apachectl start
  1. 配置vhost
    因为我用到了反向代理的功能,因此需要启用它。
1
2
3
4
5
6
7
8
# 启用vhost
vi /apache24/conf/httpd.conf
# 找到并解注
Include conf/extra/httpd-vhosts.conf
#
LoadModule proxy_module modules/mod_proxy.so
#
LoadModule proxy_http_module modules/mod_proxy_http.so

最后,我们可以通过curl -i http://127.0.0.1/来测试一下页面