您的位置:首页 > 运维架构 > Apache

编译安装apache

2016-03-18 14:29 609 查看
一、编译安装apache2.4
1、下载所需的软件源码包,使用wget命令进行下载:
apr-1.5.1:wget http://mirrors.hust.edu.cn/apache//apr/apr-1.5.1.tar.bz2 apr-util-1.5.3:wget http://mirrors.hust.edu.cn/apache//apr/apr-util-1.5.3.tar.bz2 httpd-2.4.10:wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.10.tar.bz2 2、解决依赖关系
(1)使用yum安装系统所需的一些依赖库
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers pcre pcre-devel

(2) 先编译安装apr
tar jxf apr-1.5.1.tar.bz2
cd apr-1.5.1
./configure --prefix=/usr/local/apr
make && make install

(3) 再编译安装apr-util
tar jxf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #(注意:--with-apr=/usr/local/apr是上面安装apr的路径)
make && make install

3、正式编译安装httpd
tar jxf httpd-2.4.10.tar.bz2
cd httpd-2.4.10
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event
make && make install

4、配置httpd
(1)为httpd提供sysv服务启动与关闭脚本,把以下内容复制成/etc/init.d/httpd,并且给予此文件执行权限(chmod +x /etc/rc.d/init.d/httpd),就可以直接使用service httpd 的命令形式控制httpd服务:
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
(2)把httpd服务添加为开机自启动:
chkconfig --add httpd
chkconfig httpd on
(3)修改httpd主配置文件/etc/httpd/httpd.conf,指定httpd服务的PID文件,直接在配置文件添加如下字段:
PidFile "/var/run/httpd.pid"

(4)启动httpd服务,并进行访问测试
service httpd start
(注:如果启动的时候出现这个警告:httpd: apr_sockaddr_info_get() failed for longren
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName,解决方法:在/etc/httpd/httpd.conf添加ServerName 127.0.0.1)
访问测试:http://your_ipadress,如果出现It Works,就证明httpd编译安装成功。

本文出自 “山猫” 博客,谢绝转载!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: