下载httpd-2.2.6.tar.bz2 把httpd-2.2.6.tar.bz2放到/soft 下
[[email protected] ~]#cd /soft
[[email protected] soft]#tar jxvf httpd-2.2.6.tar.bz2 //解压apache的压缩包
[[email protected] soft]#cd httpd-2.2.6 //定位到httpd-2.2.6 文件夹下
[[email protected] httpd-2.2.6]#ls //查看显示httpd-2.2.6 文件夹下内容
[[email protected] httpd-2.2.6]#./configure --help | more //查看安装apache配置参数
[[email protected] httpd-2.2.6]#./configure --prefix=/usr/local/apache --enable-so // 配置apache路径
运行./configure 命令进行编译源代码,
--prefix=/usr/local/apach2 是设置编译安装到的系统目录,
--enable-s 参数是使httpd服务能够动态加载模块功能,
--enable-rewrite 是使httpd服务具有网页地址重写功能。
[[email protected] httpd-2.2.6]#make //编译apache
[[email protected] httpd-2.2.6]#make install //安装apache
[[email protected] httpd-2.2.6]#cd /usr/local/apache //进入apache的目录
[[email protected] apache]# cd conf/
[[email protected] conf]#cp -a httpd.conf httpd.conf- //备份apache配置文件
[[email protected] conf]#chkconfig --list httpd //查看httpd服务是否已存在
[[email protected] conf]#chkconfig httpd off //关闭系统自带了httpd的服务,如果存在httpd服务
[[email protected] conf]#service httpd status //查看自带httpd服务状态
[[email protected] conf]#/usr/local/apache/bin/apachectl -k start //linux启动apache命令
[[email protected] conf]#netstat -an | grep :80 //查看linux80端口是否开启
[[email protected] conf]#ps -aux | grep httpd //linux下查看apache进程
[[email protected] conf]#cd ../..
[[email protected] local]#cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache //拷贝apache启动脚本
[[email protected] local]#vi /etc/rc.d/init.d/apache // 这里是编辑apache启动脚本
在开头的#!/bin/sh 下面加上#chkconfig: 2345 85 15
- 保存后退出vi编辑器,执行下面的命令增加Apache服务控制脚本执行权限:
chmod +x /etc/init.d/apache
[[email protected] local]#chkconfig --add apache //添加apache服务
[[email protected] local]#chkconfig --list apache //列出apache服务
- 命令输出类似下面的结果:
apache 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明apache服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制Apache的启动和停止。
[[email protected] local]#service apache stop //停止apache服务
[[email protected] local]#netstat -an | grep :80 //查看linux的80端口是否关闭
[[email protected] local]#ps -aux | grep httpd //查看是否存在httpd服务,若果之前自带httpd服务启动的话会导致新添加的apache服务启动失败
[[email protected] local]#service apache start //启动apache服务
- 执行下面的命令关闭开机自启动: chkconfig apache off
打开你的服务器ip地址,看看是否出现了tomcat的默认首页,如果出现的话,那么恭喜你
linux下安装apache已经成功了