日期:2014-05-17  浏览次数:20808 次

apache的安装
1. apache安装
    软件获取:http://httpd.apache.org/现在最新的版本是httpd-2.2.19
1.1 redhat自带apache
    查看linux自带安装apache信息:
    rpm –qa | grep httpd –i XXXX
1.2 根据源代码编译安装(以apache安装在/opt/apache2目录为例)
   执行下列命令安装
# tar zxvf httpd-2.2.19.tar.gz
# cd httpd-2.2.19
# ./configure --prefix=/opt/apache2     //安装路径
# make
# make install

    现在已经将 httpd-2.2.19 安装在 /opt/apache2.
    如果需要安装rewrite、speling、expires、headers等组件,可直接使用如下命令进行安装:
./configure --prefix=/opt/apache2 \
--enable-rewrite=shared \
--enable-speling=shared \
--enable-expires=shared \
--enable-headers=shared 
make
make install

    启动apache:/opt/apache2/bin/apachectl start
然后在IE中访问:http://机器名或IP,如果出现 It works的页面,则安装成功。
    如果成功,可以停止 Apache 服务器:/opt/apache2/bin/apachectl stop
安装成功后还需要修改apache中的httpd.conf,否则打开网页中的链接时会发生错误。修改如下,
120行左右
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from All
</Directory>
167行左右
 AllowOverride All 
273行左右
<Directory "/opt/apache2/cgi-bin">
    AllowOverride All
    Options None
    Order allow,deny
    Allow from All
</Directory>

#vi /etc/rc.d/rc.local

    添加:
    /var/www/bin/apachectl start ---开机自动启动apache服务
2. apache启动
2.1 redhat自带apache的启动或停止等操作
# /lusen/apache2/bin/apachectl start
# /lusen/apache2/bin/apachectl stop
# /lusen/apache2/bin/apachectl restart
# /lusen/apache2/bin/apachectl status


# /etc/init.d/httpd start
# /etc/init.d/httpd stop
# /etc/init.d/httpd restart
# /etc/init.d/httpd status

2.2 根据源代码编译安装的apache的启动或停止等操作
# /lusen/apache2/bin/apachectl start
# /lusen/apache2/bin/apachectl stop
# /lusen/apache2/bin/apachectl restart
# /lusen/apache2/bin/apachectl status

也可以先进行如下配置操作:
(1) 在/etc/rc.d/rc.local中增加启动apache的命令,例如:/lusen/apache2/bin/apachectl start
(2)将apache注册为系统服务
(2.1)将apachectl命令拷贝至/etc/rc.d/init.d目录下,改名为httpd
(2.2)使用编辑器打开httpd文件,并在第一行#!/bin/sh下增加两行文字如下
# chkconfig: 35 70 30
# description: Apache

(2.3)执行如下命令,注册该服务
chkconfig --add httpd

可以用下面的命令来查询所有的apache进程
ps aux | grep httpd

然后便可以以下列命令来启动或停止所有apache服务
# service httpd start
# service httpd stop
# service httpd restart
# service httpd status

3. apache目录结构
3.1 redhad linux自带apache目录结构
目录描 述
Web站点目录/var/wwwApache web站点文件目录
/var/www/html存放Web站点的Web文件
/var/www/cgi-bin存放CGI程序文件
/var/www/html/manual存放服务器手册
配置文件.htaccess基于目录的配置文件。.htaccess文件包含对它所在目录中文件的访问控制指令
/etc/httpd/conf存放配置文件
/etc/httpd/conf/httpd.confApache Web服务器主配置文件
启动脚本/etc/rc.d/init.d/httpd存放Web服务器守护进程的启动脚本
/etc/rc.d/r