0%

Apache 安装笔记

CentOS 6.5 官方支持的Apache版本为Apache/2.2.15 (Unix),如果要安装最新版本的Apache,则可以通过源码编译安装的方式实现。本文以CentOS 6.5为例,记录源码编译安装Apache的方法。主要步骤如下所述:

环境要求

The following requirements exist for building Apache httpd:

  • APR and APR-Util
  • Perl-Compatible Regular Expressions Library (PCRE)
  • Disk Space
  • ANSI-C Compiler and Build System
  • Accurate time keeping
  • Perl 5 [OPTIONAL]

根据官网教程,通过源码编译安装需要一些基础环境,比如:APR、PCRE、C编译器等。

APR、APR-Util我之前已经根据APR官网文档通过源码编译安装的方式进行安装,简述如下:

  1. 下载APR、APR-Util的源代码并解压
  2. 分别进入解压后的目录,两者均使用默认的./configure
  3. make && sudo make install

通过上述步骤安装之后,APR、APR-Util被安装至目录:/usr/local/apr/,如下所示:

/usr/local/apr/bin/
├── apr-1-config
└── apu-1-config

PCRE我之前使用了yum进行了安装

$ sudo yum -y install pcre-devel

编译、安装

下载解压Apache源代码之后,使用 ./configure --help可以查看编译选项,如果没有指定--prefix选项,默认安装目录为/usr/local/apache2,我使用了缺省值。为了使用APR, APR-Util、PCRE,需要使用--with-apr--with-apr-util--with-pcre。命令如下所示:

$ ./configure --with-apr=/usr/local/apr/bin/apr-1-config \
    --with-apr-util=/usr/local/apr/bin/apu-1-config \
    --with-pcre=/usr/bin/pcre
$ make && sudo make install

Apache官网教程使用的是--with-included-apr,我没有尝试,原文如下所述:

APR and APR-Util
Make sure you have APR and APR-Util already installed on your system. If you don’t, or prefer to not use the system-provided versions, download the latest versions of both APR and APR-Util from Apache APR, unpack them into ./srclib/apr and ./srclib/apr-util (be sure the directory names do not have version numbers; for example, the APR distribution must be under ./srclib/apr/) and use ./configure’s –with-included-apr option. On some platforms, you may have to install the corresponding -dev packages to allow httpd to build against your installed copy of APR and APR-Util.

测试是否安装成功

启动Apache:

$ sudo /usr/local/apache2/bin/httpd -k start

打开浏览器,访问localhost,如果页面显示It works!,则安装Apache成功。