1.下载

1
2
cd /usr/local/src/
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz

2.解压

1
tar -zxvf httpd-2.2.31.tar.gz

3.配置编译参数

1
2
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 [1] –enable-deflate=shared 表示共享的方式编译deflate,后面的参数同理。如果这一步你出现了这样的错误:error: mod_deflate has been requested but can not be built due to prerequisite failures

解决办法是

1
yum install -y zlib-devel

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

1
yum install -y pcre pcre-devel apr apr-devel
1
2
make
make install

以上两个步骤都可以使用 echo $? 来检查是否正确执行,否则需要根据错误提示去解决问题。

1
vim /usr/local/apache2/conf/httpd.conf

将ServerName那行的井号去掉就行了

启动

1
/usr/local/apache2/bin/apachectl start

查看模块

1
/usr/local/apache2/bin/apachectl -M

查看静态模块:查看模块:/usr/local/apache2/bin/apachectl -l

查看配置文件有无语法错误,查看模块

1
/usr/local/apache2/bin/apachectl -t

配置文件位置:/usr.local/apach2/conf/httpd.conf