首页 > 代码库 > Linux Apache 编译安装;
Linux Apache 编译安装;
Apache是常用的WEB服务端工具,在linux上称作httpd,服务名也是httpd;
在CentOS 6上默认自带httpd2.2版本,7上默认是2.4版本;
2.4的http支持使用event模型(每个线程对应一个客户请求);
在编译安装之前需要确定apr,和apr-util已经安装,在编译安装apr-util时需要制定apr的安装路径即--with-apr=/some/PATH
# mkdir /src //创建一个存放源码包的目录;
到apache官网下载httpd2.4的src源码包httpd-2.4.25.tar.bz2;
# tar -xf httpd-2.4.25.tar.bz2 //将源码包解压;
# cd httpd-2.4.25 //进入解压后的目录;
# ./configure --help //查询./configure的帮助文档;
# ./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enabel-so --enable-ssl --enable-cgi --enable-rewrit --with-zlib --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
--prefix= //表示安装目录的位置;
--sysconfdir= //配置文件的安装位置;
--enable-so //开启动态装卸载模块功能;
--enable-ssl //开启ssl功能;
--enable-cgi //允许执行cgi脚本;
--enable-rewrite //开启重写功能;
--enable-modules=[all | most] //all表示开启所有模块,most表示开启大部分模块;
--enable-mpms-shared=all //指定要编译的mpm模块;
--with-zlib //支持zlib压缩;
--with-apr //指定apr的路劲,不指定则默认自行查找;
--with-apr-util //指定apr-util的路径位置;
--with-pcre //指定pcre;
--with-mpm= //指定默认使用的mpm模式;
# make && make install
# ln -sv /usr/local/httpd/include /usr/include //将开发可用的头文件制成连接以供后续开发用;
# vim /etc/man.config //导出新的man帮助文档;
MANPATH /usr/local/httpd/man
# vim /etc/profile.d/httpd.sh //导出可执行文件;
echo PATH=/usr/local/httpd/bin:$PATH
最后添加服务脚本
提供SysV服务脚本/etc/rc.d/init.d/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
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
Linux Apache 编译安装;