第一步:linux安装apache:转自:http://www.cnblogs.com/fly1988happy/archive/2011/12/14/2288064.html
1.获取软件: http://httpd.apache.org/ httpd-2.2.21.tar.gz
2.安装步骤:
解压源文件:
1 tar zvxf httpd-2.2.21.tar.gz
2 cd httpd-2.2.21
3 ./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
4 make(这里可能会报错误:make command………………解决方法:一般出现这个-bash: make: command not found提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make、vim等常用命令,直接yum安装下即可;yum -y install gcc automake autoconf libtool make)
5 make install
运行./configure 命令进行编译源代码,
--prefix=/usr/local/apach2 是设置编译安装到的系统目录,
--enable-s 参数是使httpd服务能够动态加载模块功能,
--enable-rewrite 是使httpd服务具有网页地址重写功能。
3.启动apache:
/usr/local/apache2/bin/apachectl start
4.将apache加入到系统服务,用service命令来控制apache的启动和停止
- 首先以apachectl脚本为模板生成Apache服务控制脚本:
grep -v "#" /usr/local/apache2/bin/apachectl > /etc/init.d/apache
- 用vi编辑Apache服务控制脚本/etc/init.d/apache:
vi /etc/init.d/apache
- 在文件最前面插入下面的行,使其支持chkconfig命令:
#!/bin/sh
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.
- 保存后退出vi编辑器,执行下面的命令增加Apache服务控制脚本执行权限:
chmod +x /etc/init.d/apache
- 执行下面的命令将Apache服务加入到系统服务:
chkconfig --add apache
- 执行下面的命令检查Apache服务是否已经生效:
chkconfig --list apache
- 命令输出类似下面的结果:
apache 0:off 1:off 2:on 3:on 4:on 5:on 6:off
表明apache服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制Apache的启动和停止。
- 启动Apache服务: service apache start
- 停止Apache服务: service apache stop
- 执行下面的命令关闭开机自启动: chkconfig apache off
第二步:如果想在主机上访问虚拟机的linux就必须将虚拟机的防火墙关闭,关闭方法:
转自:http://kiddwyl.iteye.com/blog/67708
1) 重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop
永久关闭:
chkconfig --level 2345 iptables off
需要说明的是对于Linux下的其它服务都可以用以上命令执行开启和关闭操作。
在开启了防火墙时,做如下设置,开启相关端口,
修改/etc/sysconfig/iptables 文件,添加以下内容:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
第三步:解决httpd: Could not reliably determine the server's fully qualified domain name,
转自:http://www.cnblogs.com/52linux/archive/2012/03/24/2415637.html
用记事本打开 httpd.conf
将里面的 #ServerName localhost:80 注释去掉即可。
再执行 httpd
然后可以通过浏览器访问 http://localhost:80 ,如果页面显示 “It works!” ,即表示apache已安装并启动成功。