码迷,mamicode.com
首页 > Web开发 > 详细

CentOS6.5安装Apache服务

时间:2015-04-10 22:29:18      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:centos6.5   安装apache服务   linux   配置防火墙   安装gcc   

一、描述

CentOS安装Apache服务可以有两种方式,一种是用yum安装,一种是从官网下载源代码进行安装。


二、使用yum安装Apache服务

步骤1:在命令行输入如下语句可以使用yum在线更新方式进行安装:

[tong@tong /]$ sudo yum install httpd -y 

注意:采用该方式进行安装配置文件的默认路径为:/etc/httpd/conf/httpd.conf

步骤二:配置防火墙,添加下面红色字体的一行,表示开启80端口供客户浏览。

[tong@tong /]$ sudo vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

步骤三:配置完防火墙之后需要重新启动防火墙

[tong@tong /]$ sudo service iptables restart
iptables: Setting chains to policy ACCEPT: filter [  OK  ]
iptables: Flushing firewall rules: [  OK  ]
iptables: Unloading modules: [  OK  ]
iptables: Applying firewall rules: [  OK  ]

步骤四;Apache配置完成后,则可启动服务

[tong@tong /]$ sudo service httpd start
Starting httpd: httpd: apr_sockaddr_info_get() failed for tong
httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName
[  OK  ]

注意:虽然这里可以启动但是报错,这是因为没有在Apache服务器的配置文件中添加ServerName参数,所以我们要在配置文件中配置这个参数

步骤5:我们查看我们的hostname主机名,并将该主机名添加到Apache配置文件的ServerName参数中

[tong@tong /]$ hostname
tong
[tong@tong /]$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=tong

由上述的hostname为tong,则编辑Apache配置文件

[tong@tong conf]$ sudo vi /etc/httpd/conf/httpd.conf

在其中加入一行:ServerName tong:80

步骤5:重新启动Apache服务,则不会报错

[tong@tong conf]$ sudo service httpd restart
Stopping httpd: [  OK  ]
Starting httpd: [  OK  ]

步骤6:测试范例网页

在本机浏览器输入:http://本机IP地址,我的IP为:192.168.200.5,,我在浏览器上输入:http://192.168.200.5

结果显示:

技术分享

三、使用源代码安装Apache服务

步骤1:下载源代码文件

[tong@tong tongSoftware]$ sudo wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.12.tar.gz

步骤2;解压并安装

[tong@tong tongSoftware]$ sudo tar xzvf httpd-2.4.12.tar.gz

进入该解压后的目录,输入如下命令:

[tong@tong httpd-2.2.29]$ sudo ./configure

configure: error: in `/usr/local/tongSoftware/httpd-2.2.29/srclib/apr‘:
configure: error: no acceptable C compiler found in $PATH
See `config.log‘ for more details
configure failed for srclib/apr

系统提示未安装gcc编译器,则安装该编译器

[tong@tong httpd-2.2.29]$ sudo yum install gcc

安装成功后重新编译源文件:

[tong@tong httpd-2.2.29]$ sudo ./configure          //检查安装平台是否支持安装

[tong@tong httpd-2.2.29]$ sudomake  //根据安装平台进行编译

[tong@tong httpd-2.2.29]$ sudomake install        //安装软件

然后按照之前用yum安装的方法配置防火墙,启动Apache服务。


CentOS6.5安装Apache服务

标签:centos6.5   安装apache服务   linux   配置防火墙   安装gcc   

原文地址:http://blog.csdn.net/tongyuehong137/article/details/44983867

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!