源码编译安装httpd 2.4

加方法一

上传已下载压缩包或者使用wget获取源代码压缩包

wget https://archive.apache.org/dist/httpd/httpd-2.4.54.tar

安装编译工具

yum install gcc gcc-c++ make -y

解压

tar xf httpd-2.4.62.tar.gz  -C /usr/local/src/

创建用户和组

groupadd -r -g 48 apache
useradd -r -u 48 -g 48 -c "Apache server" -s /sbin/nologin apache

配置Apache服务器

./configure --prefix=/usr/local/apache

安装时提示依赖未安装,看提示安装依赖

...

安装依赖

yum list | grep -i apr
yum install apr-devel -y
yum install apr-util-devel -y

安装开发包

yum install pcre-devel -y

编译和安装

make
make install

 拷贝脚本后修改

cp apachectl /etc/init.d/httpd
vim /etc/init.d/httpd

添加并启用服务

chkconfig --level 35 --add httpd  
chkconfig --level 35 httpd on ---开机自启

 启动服务,查看状态

方法二

创建脚本

vim /etc/init.d/httpd

脚本内容:
#!/bin/bash
. /etc/rc.d/init.d/functions
 
apachectl=/usr/local/httpd/bin/apachectl
httpd=/usr/local/httpd/bin/httpd
prog=httpd
start() {
    echo -n $"Starting $prog: "
    daemon $httpd $OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
    return $RETVAL
}
 
stop() {
    echo -n $"Stopping $prog: "
    killproc $httpd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd
    return $RETVAL
}
 
# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status $httpd
    ;;
  restart)
    stop
    start
    ;;
  condrestart)
    if [ -f /var/lock/subsys/httpd ]; then
        stop
        start
    fi
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
    exit 1
esac
 
exit $?

给权限 

chmod +x /etc/init.d/httpd

 添加服务和开机自启动

chkconfig --level 35 --add httpd  
chkconfig --level 35 httpd on ---开机自启

 启动,查看状态

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值