CentOS 下安装Apache

本文提供了 Apache HTTP Server 的全面指南,包括使用 yum 和源码安装的方法,配置 Apache 开机启动,以及停止、重启 Apache 的操作。此外,还介绍了如何设置环境变量、安装依赖包,并通过步骤说明确保 Apache 正常运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.采用yum安装

#yum install httpd

配置Apache开机启动

#chkconfig --levels 235 httpd on

启动Apache

#/etc/init.d/httpd start


2.采用源码安装

(1)安装包下载

httpd-2.4.4.tar.gz http://httpd.apache.org/download.cgi 

apr-1.4.8.tar.gz    http://apr.apache.org/ (依赖包)

apr-util-1.5.2.tar.gz http://apr.apache.org/(依赖包)


(2)安装

  • 安装apr
#cd /root/Downloads 进入安装包存放的目录
#tar -zxvf apr-1.4.8.tar.gz  
#cd apr-1.4.8
#./configure
#make
#make install

  • 安装apr-util
#cd /root/Downloads
#tar -zxvf apr-util-1.5.2.tar.gz
#cd apr-util-1.5.2
#./configure --with-apr=/usr/local/apr
#make
#make install
  • 安装Apache
#cd /root/software
#tar -zxvf httpd-2.4.4.tar.gz
#cd httpd-2.4.4
#./configure -prefix=/usr/local/apache -enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr/ --with-pcre=/usr/local/pcre/
#make
#make install

  • 设置开机启动
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
在在#!/bin/sh后面加入下面两行
#chkconfig:345 85 15
#description: Start and stops the Apache HTTP Server.
然后
chmod +x /etc/rc.d/init.d/httpd
chkconfig --add httpd
然后可以用setup命令进入服务设置,设置为开机启动


  • 添加环境变量

vim /etc/profile
在最下面添加两行
export APACHE=/usr/local/apache
export PATH=${APACHE}/bin:$PATH
保存退出
#source /etc/profile
测试是否安装成功:httpd -v.


3.Apache的停止与重启

优雅重启:apachectl -k graceful

立即重启:apachectl -k restart

优雅停止:apachectl -k graceful-stop

立即停止:apachectl -k stop

参见:http://lamp.linux.gov.cn/Apache/ApacheMenu/stopping.html







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值