apache官方网站下载地址 下载的版本根据你的平台和需求而定。
下载apache到/usr/local/src/
[root@localhost mysql]# cd /usr/local/src/[root@localhost src]# wget http://mirrors.sohu.com/apache/httpd-2.2.31.tar.bz2
解压
[root@localhost src]# tar jxf httpd-2.2.31.tar.bz
配置编译参数
[root@localhost src]# cd httpd-2.2.31[root@localhost 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,后面的参数同理。
常见错误
error: mod_deflate has been requested but can not be built due to prerequisite failures
解决办法是:
[root@localhost httpd-2.2.31]# yum install -y zlib-devel
为了避免在make的时候出现错误,所以最好是提前先安装好一些库文件:
[root@localhost httpd-2.2.31]# yum install -y pcre pcre-devel apr apr-devel
checking for chosen layout... aprchecking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure: error: in `/usr/local/src/httpd-2.2.31/srclib/apr':configure: error: no acceptable C compiler found in $PATHSee `config.log' for more detailsconfigure failed for srclib/apr
解决办法是:
[root@localhost httpd-2.2.31]# yum install -y gcc
编译
[root@localhost httpd-2.2.31]# make
安装
[root@localhost httpd-2.2.31]# make install
以上两个步骤都可以使用 echo $?
来检查是否正确执行,否则需要根据错误提示去解决问题。
启动Apache服务
[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl start
httpd: Could not reliably determine the server's fully qualified domain name, us ing 127.0.0.1 for ServerNamehttpd (pid 10275) already running
解决办法是:
修改/usr/local/apache2/conftpd.conf里面的ServerName即可。
重启Apache服务
[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl restart[root@localhost httpd-2.2.31]# /usr/local/apache2/bin/apachectl graceful
以上两个命令都是重启的命令,区别:第一个是杀死原来的进程,从新在开启一个进程;第二个是在原来进程还存在,只是把配置文件再加载了一次。