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