httpd源码安装

#HTTPD编译安装步骤详解
httpd属于Apache软件基金会组织,官网地址:https://www.apache.org
.
安装HTTPD需要先解决其依赖关系,安装gcc、pcre、expat、apr、apr-util。
gcc、pcre、expat使用yum安装即可:
yum install -y gcc* pcre-devel expat-devel
.
arp和arp-util是一个共享的函数库,他的功能使httpd不用考虑底层操作系统的不同,可以方便移植。
.
arp使用编译安装
链接:http://apr.apache.org/download.cgi/arp-1.7.0.tar.gz
我们将arp和arp-util下载到/usr/local/src/目录下,使用源码包安装过程安装。
tar xf arp-1.7.0.tar.gz
cd apr-1.7.0
./configure --prefix=/usr/local/apr #注:可以使用./configuer -help 查看其他参数,这里不做解释;
make && make install
.
apr-util也是用源码方式安装
链接:http://apr.apache.org/download.cgi/arp-util-1.6.1.tar.gz
tar xf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #--with-apr是声明apr的位置,因为apr-util是依赖apr的工具包。
make && make install
这样我们就解决了依赖关系了,开始准备httpd;
.
官网下载地址:http://httpd.apache.org/download.cgi#apache24
将源码包同样放在/usr/local/src/目录下
tar xf httpd-2.4.39.tar.gz
cd httpd-2.4.39
./configure --prefix=/usr/local/httpd --sysconfdir=/etc/httpd --enable-so --enable-mod_ssl --enable-cgi --enable-cgid --enable-rewirte --enbale-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util #注:./configure可以查看其他参数,根据自己需要添加。
make && make install
.
以下是httpd源码编译参数介绍:
--prefix=/usr/local/httpd #配置httpd安装路径
--sysconfdir=/etc/httpd #httpd主配置文件路径
--enable-so #支持动态共享模块
--enbale-mod_ssl #启用ssl功能,不启用则无法使用https功能
--enable-cgi #支持cgi协议
--enable-cgid #如果使用vorker和event模式则需要加此项
--enable-rewirte #支持URL重写的功能
--enable-modules=most #启用模块功能,most(大多数的),all(全部的),few(少数的)
--enable-mods-shared=most #启用共享模块
--enable-mpms-shared=all #mpm(多道处理模块),all表示三种模式都会做成模块添加(prefork、vorker、event)
--with-apr=/usr/local/apr #声明apr安装位置
--with-apr-util=/usr/local/apr-util #声明apr-util安装位置
.
安装完成后在/usr/local/httpd/目录下会生成一下目录
bin:二进制程序文件
cgi-bin:执行cgi程序时的位置
error :存放一些错误信息
htdocs :网页文档的位置
icons :提供一些图标
include :头文件
logs :日志文件
man:帮助文件
manual :安装手册
modules:模块目录
.
httpd默认当selinux启动时,httpd启动不了,所以我们将其关掉
查看:getenforse
临时修改:setenforse 0
永久修改编辑/etc/selinux/config文件将
SELINUX=disabled
改为disabled即可
.
我们可以使用/bin/apachectl start 启动httpd服务
netstat -nlpt 查看端口是否已经监听
添加到PATH变量中,编辑文件/etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/httpd/bin
默认httpd不支持service服务,需要自己写脚本,编辑/etc/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/init.d/script_name即可
.
这样就可以轻松启动或关闭httpd服务了。

猜你喜欢

转载自blog.51cto.com/14132521/2418682