CentOS 6下编译安装httpd-2.4(方法二)

说明:前期准备工作请参考(法二不在赘述):
https://blog.csdn.net/qq_43753178/article/details/102534149

1.准备安装包:
apr-1.6.5.tar.gz
apr-util-1.6.1.tar.gz
httpd-2.4.48.tar.bz2
2.安装开发包组:

[root@grntoo ~]# yum groupinstall     "development tools"
[root@grntoo ~]# yum install openssl-devel     pcre-devel expat-devel

3.新建目录src,将所需的压缩包程序文件都放进去;

[root@grntoo ~]# mkdir src
[root@grntoo ~]# mv apr*httpd-2.4.48   src
[root@grntoo ~]# cd src/
[root@grntoo src]# tar tar xvf apr-1.6.5.tar.gz    tar xvf apr-util-1.6.1.tar.gz     tar xvf httpd-2.4.48.tar.bz2

4.把apr*整个目录拷贝进httpd-2.4.48/scrlib目录下并改名;

[root@grntoo src]# cp -a apr-1.6.5 httpd-2.4.48/srclib/apr
[root@grntoo src]# cp -a apr-util-1.6.1 httpd-2.4.48/srclib/apr-util

5.进行编译

[root@gentoo src]# cd httpd-2.4.48

[root@gentoo httpd-2.4.28]# ./configure     --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi     --enable-rewrite --with-zlib --with-pcre --with-included-apr     --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
[root@gentoo httpd-2.4.28]# make -j 4     && make install

6.配置文件

[root@gentoo ~]# cd /app/httpd24/bin
[root@gentoo bin]# vim /etc/profile.d/http24.sh
  写入: PATH=/app/httpd24/bin:$PATH

执行

 [root@gentoo ~]# ./etc/profile.d/httpd24.sh

启动服务

[root@gentoo ~]# apachectl

注意:此时要关闭防火墙以及置SElinux为disabled
访问主页面的位置为 /app/httpd24/htdocs/index.html
展示:在这里插入图片描述
扩展:
1.指定运行身份:
指定运行身份Apache首先确认系统有账户apache:id apache
如果不存在就要自己创建一个:useradd -r apache
查看apache的默认路径:getent passwd apache
查看系统自带的apache账户来源:rpm -q --scripts httpd

[root@gentoo ~]# vim /app/httpd24/conf/httpd.conf

在这里插入图片描述停止httpd进程:

[root@gentoo ~]# apachectl stop

修改启动脚本,CentOS 6 中,服务器的启动脚本存放于/etc/init.d/httpd;

[root@gentoo ~]# cd  /etc/init.d
[root@gentoo init.d]# vim  http
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible  \
#	       server implementing the current HTTP standards.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd/httpd.pid
#
### BEGIN INIT INFO
# Provides: httpd
# Required-Start: $local_fs $remote_fs $network $named
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: The Apache HTTP Server is an extensible server 
#  implementing the current HTTP standards.
### END INIT INFO

# 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/sbin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd/httpd24.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
 The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
		 echo -n $"Starting $prog: "
		 LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
		 RETVAL=$?
		 echo
		[ $RETVAL = 0 ] && touch ${lockfile}
		  return $RETVAL
}

# When stopping httpd, a delay (of default 10 second) is required
# before SIGKILLing the httpd parent; this gives enough time for the
	# httpd parent to SIGKILL any errant children.
	stop() {
	status -p ${pidfile} $httpd > /dev/null
	if [[ $? = 0 ]]; then
	echo -n $"Stopping $prog: "
			killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
		else
						echo -n $"Stopping $prog: "
						success
					fi
					RETVAL=$?
					echo
					[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
				}

				reload() {
				    echo -n $"Reloading $prog: "
				    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
				        RETVAL=6
				        echo $"not reloading due to configuration syntax error"
				        failure $"not reloading $httpd due to configuration syntax error"
				    else
				        # Force LSB behaviour from killproc
				        LSB=1 killproc -p ${pidfile} $httpd -HUP
				        RETVAL=$?
				        if [ $RETVAL -eq 7 ]; then
				            failure $"httpd shutdown"
				        fi
				    fi
				    echo
				}

				# See how we were called.
				case "$1" in
				  start)
					start
					;;
				  stop)
					stop
					;;
				  status)
				        status -p ${pidfile} $httpd
					RETVAL=$?
					;;
				  restart)
					stop
					start
					;;
				  condrestart|try-restart)
					if status -p ${pidfile} $httpd >&/dev/null; then
						stop
						start
					fi
					;;
				  force-reload|reload)
				        reload
					;;
				  graceful|help|configtest|fullstatus)
					$apachectl $@
					RETVAL=$?
					;;
				  *)
					echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
					RETVAL=2
				esac

				exit $RETVA
[root@gentoo init.d]# cp httpd httpd24
[root@gentoo init.d]# vim httpd24

在这里插入图片描述
添加进服务列表:

[root@gentoo init.d]# chkconfig --add httpd24

确认:

[root@gentoo init.d]# chkconfig --list httpd24

开机启动:

[root@gentoo init.d]#chkconfig --list httpd24chkconfig httpd24 on

启动该服务:

[root@gentoo init.d]#chkconfig --list httpd24service httpd24 start

测试:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值