Centos 编译安装 Apache 2.4 准备:
[root@NFSServer ~]# yum groupinstall "Development tools"
从http://httpd.apache.org下载最新的httpd、apr、apr-util,然后解压缩
[root@NFSServer ~]# tar zxvf apr-1.5.0.tar.gz [root@NFSServer ~]# tar zxvf apr-util-1.5.3.tar.gz [root@NFSServer ~]# tar zxvf httpd-2.4.7.tar.gz
由于现在最新的httpd-2.4都需要apr、apr-util。
1.插入方法安装
[root@NFSServer ~]# mv apr-1.5.0 httpd-2.4.7/srclib/apr [root@NFSServer ~]# mv apr-util-1.5.3 httpd-2.4.7/srclib/apr-util [root@NFSServer ~]# mkdir -p /webserver/httpd/conf [root@NFSServer ~]# cd httpd-2.4.7 [root@NFSServer httpd-2.4.7]# ./configure --prefix=/webserver/httpd --sysconfdir=/webserver/httpd/conf --with-inculded-apr --enable-deflate --enable-expires --enable-headers --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mpms-shared=all
如果在编译中出现
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
则是因为rewirte需要pcre-devel支持
[root@NFSServer httpd-2.4.7]# yum -y install pcre pcre-devel
再编译一下即可
编译完成后
[root@NFSServer httpd-2.4.7]# make && make install
2.一步一步安装
a.编译安装apr
[root@NFSServer ~]# cd apr-1.5.0 [root@NFSServer apr-1.5.0]# ./configure --prefix=/webserver/apr [root@NFSServer apr-1.5.0]# make && make install
加入在安装apr的过程中出现rm: cannot remove `libtoolT': No such file or directory
则编辑configure文件,把RM='$RM'改为RM='$RM -f'
b.编译安装apr-util
[root@NFSServer ~]# apr-util-1.5.3 [root@NFSServer apr-util-1.5.3]# ./configure --prefix=/webserver/apr-util --with-apr=/webserver/apr [root@NFSServer apr-util-1.5.3]# make && make install
c.编译安装httpd
[root@NFSServer ~]# cd httpd-2.4.7 [root@NFSServer httpd-2.4.7]# ./configure \ >--prefix=/webserver/httpd \ >--sysconfdir=/webserver/httpd/conf \ >--enable-deflate \ >--enable-expires \ >--enable-headers \ >--enable-so \ >--enable-rewirte \ >--enable-ssl \ >--enable-cgi \ >--enable-cgid \ >--enable-modules=most \ >--enable-modules-shared=most \ >--enable-mpms-shared=all \ >--with-apr=/webserver/apr \ >--with-apr-util=/webserver/apr-util
--prefix=/webserver/httpd :指定安装目标路径
--sysconfdir=/webserver/httpd/conf :指定配置文件安装位置
--enable-deflate :支持以deflate方式压缩
--enable-expires:支持客户端缓存
--enable-headers :支持头部信息
--enable-so :支持动态共享模块,如果没有这个模块PHP将无法与apache结合工作
--enable-rewirte :支持URL重写
--enable-ssl :启用支持ssl
--enable-cgi :启用支持cgi
--enable-cgid :启用支持带线状图形的CGI脚本 MPMs
--enable-modules=most :安装大多数模块
--enable-modules-shared=most :安装大多数共享模块
--enable-mpms-shared=all :支持全部多道处理方式
--with-apr=/webserver/apr :指定apr路径
--with-apr-util=/webserver/apr-util :指定apr-util路径
编译完成后
[root@NFSServer httpd-2.4.7]# make && make install
配置启动脚本:
[root@NFSServer httpd-2.4.7]# cp build/rpm/httpd.init /etc/init.d/httpd //使用init脚本管理httpd [root@NFSServer httpd-2.4.7]# vim /etc/init.d/httpd httpd=${HTTPD-/usr/sbin/httpd} 修改成 httpd=${HTTPD-/webserver/httpd/bin/httpd} pidfile=${PIDFILE-/var/run/${prog}.pid} 修改成pidfile=${PIDFILE-/webserver/httpd/logs/${prog}.pid} lockfile=${LOCKFILE-/var/lock/subsys/${prog}} RETVAL=0 # check for 1.3 configuration check13 () { CONFFILE=/etc/httpd/conf/httpd.conf 修改成CONFFILE=/webserver/httpd/conf/httpd.conf [root@NFSServer httpd-2.4.7]# chmod 755 /etc/init.d/httpd //增加执行权限 [root@NFSServer httpd-2.4.7]# chkconfig --add httpd //添加httpd到服务开机启动 root@NFSServer httpd-2.4.7]# cd /usr/sbin/ [root@NFSServer sbin]# ln -s /webserver/httpd/bin/* . 为日志文件创建软链接 [root@NFSServer sbin]# ln -s /webserver/httpd/logs /var/log/httpd
如果启动httpd的时候出现
Starting httpd: AH00557: httpd: apr_sockaddr_info_get() failed for NFSServer 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 [ OK ]
则需要修改2处:
1.修改/etc/hosts,增加一行
127.0.0.1 NFServer
2.修改 /webserver/httpd/conf/httpd.conf,增加一行
ServerName NFSServer
注意:NFSServer为机器名称
转载于:https://blog.51cto.com/fengwan/1360429