Apache HTTP Server(简称Apache)是世界使用排名第一的Web服务器软件。它是Apache软件基金会的一个开放源码的网页服务器,可以运行在几乎所有广泛使用的计算机平台上。由于其多平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩展,将Perl/Python等解释器编译到服务器中。

1: 安装Apache需要的依赖包

为了可以顺利配置和编译Apache,你需要先安装这些依赖软件:

firebird@locahost~$ sudo apt-get install build-essential
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
dpkg-dev fakeroot g++ g++-4.6 libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libdpkg-perl
libstdc++6-4.6-dev libtimedate-perl patch
After this operation, 29.0 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
....
....
....
firebird@locahost~$ sudo apt-get build-dep apache2
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
autoconf comerr-dev debhelper dh-apparmor gettext hardening-wrapper html2text intltool-debian krb5-multidev libapr1 libapr1-dev libaprutil1 libaprutil1-dev libcap-dev libexpat1-dev libgettextpo0 libgssrpc4 libkadm5clnt-mit8 libkadm5srv-mit8 libkdb5-6 libkrb5-dev libldap2-dev libmysqlclient-dev libmysqlclient18 libpcre3-dev libpcrecpp0 libpq-dev libpq5 libsqlite3-dev libssl-dev libunistring0 m4 po-debconf sharutils uuid-dev zlib1g-dev
After this operation, 46.4 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
....
....
....
Setting up hardening-wrapper (1.36ubuntu1) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

2: 下载并解压Apache源码包

firebird@locahost~$ cd /usr/local/src/
firebird@locahost:/usr/local/src$ sudo wget apache.techartifact.com/mirror//httpd/httpd-2.4.3.tar.bz2
--2012-09-17 23:56:39-- http://apache.techartifact.com/mirror//httpd/httpd-2.4.3.tar.bz2
Resolving apache.techartifact.com (apache.techartifact.com)... 111.118.180.60
Connecting to apache.techartifact.com (apache.techartifact.com)|111.118.180.60|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4559279 (4.3M) [application/x-tar]
Saving to: `httpd-2.4.3.tar.bz2'
100%[=================================================================================>] 45,59,279 60.5K/s in 71s
2012-09-17 23:57:51 (62.4 KB/s) - `httpd-2.4.3.tar.bz2' saved [4559279/4559279]
firebird@locahost:/usr/local/src$ sudo tar -jxvf httpd-2.4.3.tar.bz2
httpd-2.4.3/build/NWGNUtail.inc
httpd-2.4.3/build/pkg/
httpd-2.4.3/build/PrintPath
httpd-2.4.3/build/program.mk
...
..
.

3: 从源码安装Apache

firebird@locahost:/usr/local/src/httpd-2.4.3$ sudo ./configure --help

在运行 ./configure之前,最好先看看–help有哪些可用的选项。
然后使用你需要的选项来运行 ./configure ,如安装目录,开启的模块等。

firebird@locahost:/usr/local/src/httpd-2.4.3$ sudo ./configure --prefix=/usr/local/apache2 --enable-mods-share=all
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
configure: Configuring Apache Portable Runtime library...
configure:
....
...

编译:

firebird@locahost:/usr/local/src/httpd-2.4.3$ sudo make
/usr/share/apr-1.0/build/libtool --silent --mode=compile x86_64-linux-gnu-gcc -std=gnu99 -pthread -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -I. -I/usr/local/src/httpd-2.4.3/os/unix -I/usr/local/src/httpd-2.4.3/include -I/usr/include/apr-1.0 -I/usr/local/src/httpd-2.4.3/modules/aaa -I/usr/local/src/httpd-2.4.3/modules/cache -I/usr/local/src/httpd-2.4.3/modules/core -I/usr/local/src/httpd-2.4.3/modules/database -I/usr/local/src/httpd-2.4.3/modules/filters -I/usr/local/src/httpd-2.4.3/modules/ldap -I/usr/local/src/httpd-2.4.3/modules/loggers -I/usr/local/src/

安装:

firebird@locahost:/usr/local/src/httpd-2.4.3$ sudo make install
Making install in srclib
Making install in mpm
make[2]: Entering directory `/usr/local/src/httpd-2.4.3/server/mpm'
Making install in event
make[3]: Entering directory `/usr/local/src/httpd-2.4.3/server/mpm/event'
make[4]: Entering directory `/usr/local/src/httpd-2.4.3/server/mpm/event'

4: 启动Apache服务器

firebird@locahost:/usr/local/src/httpd-2.4.3$ sudo /usr/local/apache2/bin/apachectl start
AH00557: httpd: apr_sockaddr_info_get() failed for firebird
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message

如果你看到以上错误信息, 原因是没有在 /etc/httpd/conf/httpd.conf 中设定 ServerName。
修改httpd.conf文件,增加:

ServerName www.example.com:80

再次启动Apache:

firebird@locahost:/usr/local/src/httpd-2.4.3$ sudo /usr/local/apache2/bin/apachectl start

到这里就可以打开浏览器访问了。