centos6安装,配置,启动apache

原文地址:http://blog.csdn.net/wy3552128/article/details/8143875

对文章进行了一点小的改动,在后面加了一点自己遇到的问题和解决办法.

平台:VMware上虚拟的centos6

宿主机:windows

安装Apache前准备:

1、检查该环境中是否已经存在httpd服务的配置文件,默认存储路径:/etc/httpd/httpd.conf(这是centos预装的Apache的一个ent版本,一般我们安装源代码版的Apache)。如果已经存在/etc/httpd/httpd.conf,请先卸载或者关闭centos系统自带的web服务,执行命令:chkconfig  httpd off,再或者把centos自带的httpd服务的80端口改为其他端口,只要不与我们安装的Apache服务的端口冲突就可以啦。

停止并卸载Linux系统自带的httpd服务:

1、service httpd stop

2、ps -ef | grep httpd

3、kill -9 pid号(逐个删除)

4、rpm -qa |grep httpd

5、rpm -e httpd软件包

[html] view plain copy
  1. [root@localhost bin]# find / -name httpd.conf  
  2. [root@localhost bin]#   
2、下载Apache安装包(httpd-2.4.29.tar.gz,下载地址:http://httpd.apache.org/
在安装Apache时,我分别针对不同版本进行了安装,在编译时是不同的,configure后跟的参数不同。

httpd-2.2.23版本编译命令:

[html] view plain copy
  1. ./configure --prefix=/usr/local/apache2 (安装目录参数后面可以不加任何参数,直接安装即可)  
  2. make  
  3. make install  
httpd-2.4.29版本编译命令:
[html] view plain copy
  1. ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre (除了指定Apache的安装目录外,还要安装apr、apr-util、pcre,并指定参数)  
  2. make  
  3. make install  
在编译Apache(在安装httpd-2.4.29时遇到的问题)时分别出现了apr not found、APR-util not found、pcre-config for libpcre not found的问题,下面就httpd-2.4.29的这些问题解决来实际操作一把。
http://apr.apache.org/download.cgi  下载apr-1.6.3.tar.gz、apr-util-1.6.1.tar.gz
http://sourceforge.net/projects/pcre/files/latest/download 下载pcre-8.31.zip  #######这里原作者放错地址了,这个地址下下来的是pcre2.10.20   转好后安装会出现找不到一个包的问题,解决办法是下载pcre重新装.

https://sourceforge.net/projects/pcre/files/pcre/8.41/
1.解决apr not found问题

[html] view plain copy
  1. [root@localhost bin]# tar -zxf apr-1.6.3.tar.gz  
  2. [root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr  
  3. [root@localhost apr-1.6.3]# make  
  4. [root@localhost apr-1.6.3]# make install  
2.解决APR-util not found问题
[html] view plain copy
  1. [root@localhost bin]# tar -zxf apr-util-1.3.12.tar.gz  
  2. [root@localhost apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config  
  3. [root@localhost apr-util-1.6.1]# make  
  4. [root@localhost apr-util-1.6.1]# make install  
3、解决pcre-config for libpcre not found问题
[html] view plain copy
  1. [root@localhost ~]# unzip pcre-8.41.zip  
  2. [root@localhost ~]# cd pcre-8.41  
  3. [root@localhost pcre-8.41]# ./configure --prefix=/usr/local/pcre  
  4. [root@localhost pcre-8.41]# make
  5. [root@localhost pcre-8.41]# make install  
如果已经存在/etc/httpd/httpd.conf,请先卸载或者关闭centos系统自带的web服务,执行命令:chkconfig  httpd off,再或者把centos自带的httpd服务的80端口改为其他端口,只要不与我们安装的Apache服务的端口冲突就可以啦。
启动Apache:/usr/local/apache2/bin/apachectl start
停止Apache:/usr/local/apache2/bin/apachectl stop
重启Apache:/usr/local/apache2/bin/apachectl restart

网站放在/usr/local/apache2/htdocs目录下

在IE中通过http://localhost:80,如果看到页面中显示“It works!”字样,则代表Apache验证通过。如果网站的index后缀是PHP格式的,则要修改httpd.conf配置文件(/usr/local/apache2/conf),在DirectoryIndex增加 index.php。
[html] view plain copy
  1. #  
  2. # DirectoryIndex: sets the file that Apache will serve if a directory  
  3. # is requested.  
  4. #  
  5. <IfModule dir_module>  
  6.     DirectoryIndex index.html index.php  
  7. </IfModule>  


ps:我在装的时候,主要是遇到了两个问题:

一,在启动Apache的时候报错httpd: apr_sockaddr_info_get() failed  还有个ServerName的报错.

这个原因是在etc/hostes 中加入你的主机名  和在apache的配置文件 bin/conf/httpd.conf  中 ServerName 把前面的# 打掉  如果需要远程的话 在后面改写成你本机IP


二.在因为我需要远程,所以在apache already running 正常可以启动后,要在bin/conf/httpd.conf 中修改  

<Directory />
    AllowOverride none
    Require all granted  #默认是 Require all deny


然后一定要修改防火墙,因为apache默认是 listen 80端口,首先确定原来80端口未被占用

netstat -ntpl |grep 80 

然后,

防火墙配置

注意如果你希望在本地机器例如xp访问虚拟机的网页,如果是centos6需要修改防火墙启动80端口

cd /etc/sysconfig

修改iptables文件,或者直接用vim编辑

vim /etc/sysconfig/iptables

添加下面一行,打开防火墙80端口:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

重启防火墙
# /etc/init.d/iptables restart

查看CentOS防火墙信息:/etc/init.d/iptables status

关闭CentOS防火墙服务:/etc/init.d/iptables stop


我是直接把防火墙关闭了.                ############每次配置完httpd.conf文件后需要对apache进行重启


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章