4532423 发表于 2016-7-6 10:06:00

LAMP--2.Apache 编译安装

   apache 官网下载地址:http://www.apache.org/dyn/closer.cgi 。建议使用国内开源镜像地址:http://mirrors.aliyun.com/apache/httpd/httpd-2.2.31.tar.bz2或 http://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2 。所谓的apache,真正的名字是 httpd。   
         下载

1
2
# cd /usr/local/src
# wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2




         解压


1
# tar jxvf httpd-2.2.31.tar.bz2




         配置编译参数


1
2
3
4
5
6
7
8
9
# cd httpd-2.2.31
#./configure \
--prefix=/usr/local/apache2 \
--with-included-apr \
--enable-so \
--enable-deflate=shared \
--enable-expires=shared \
--enable-rewrite=shared \
--with-pcre




      --prefix 指定安装到哪里, --enable-so表示启用DSO,--enable-deflate=shared表示动态共享的方式编译deflate模块,后面的参数同理。既然有动态那当然也有静态了,这两者有什么区别呢?apache 编译安装完成后会生成一个核心的二进制可执行文件叫做 httpd,这个文件作为核心文件,提供服务时就是它在处理用户的请求,但是有些功能,比如这里提到的expires就是配置静态文件(图片)过期时间的,也就是说图片可以在用户浏览器的临时缓存目录中缓存多久。这些功能是作为 httpd 的一个扩展模块来工作的,那么这种扩展模块有两种存在的方式,一种是直接在编译的时候和 httpd 文件结合在一起,组成一个体积大的文件,这种方式就叫做静态。而另外一种方式是,扩展模块作为一个独立的文件存在,只有在使用这个模块时再去调用它,这种方式就是动态共享。其中,动态的好处是,核心文件 httpd 比较小,模块随时用随时加载,耗费内存相对较少。而静态的优势是,在服务启动时,会把所有模块加载,到用时很快就执行,效率较高。

      ./configure 这一步经常会出现错误:

1
2
error: mod_deflate has been requested but can not be built due to prerequisite failures
# yum install -y zlib-devel




      为了避免在 make 的时候出现错误,最好是提前先安装好一些库文件:

1
#yum install -y pcre pcre-devel apr apr-devel




         编译和安装

#make
#make install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# make
make: Leaving directory `/usr/local/src/httpd-2.2.31/modules/mappers'
make: Leaving directory `/usr/local/src/httpd-2.2.31/modules/mappers'
make: Leaving directory `/usr/local/src/httpd-2.2.31/modules'
make: Entering directory `/usr/local/src/httpd-2.2.31/support'
make: Leaving directory `/usr/local/src/httpd-2.2.31/support'
make: Leaving directory `/usr/local/src/httpd-2.2.31'
# echo $?
0
# make install
make: Entering directory `/usr/local/src/httpd-2.2.31/support'
make: Leaving directory `/usr/local/src/httpd-2.2.31/support'
Installing configuration files




Installing header files
Installing build system files
Installing man pages and online manual
make: Leaving directory `/usr/local/src/httpd-2.2.31'
# echo $?
0






    apache 启动脚本加入系统服务列表

1
2
# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
# vim /etc/init.d/httpd




    在第一行#!/bin/sh 下面添加两行文字


1
2
#chkconfig: 35 70 30
#description: Apache




    保存退出


1
2
# chkconfig --add httpd
# chkconfig --level 35 httpd on







页: [1]
查看完整版本: LAMP--2.Apache 编译安装