milaoshu

Apache安装

 

 

 

 

 

 

 

 

 

Apache配置

  1. 访问网页的流程,以http://www.sohu.com/news.html为例:

a)    解析主机www.sohu.com:首先是查询本地文件windows/sys32/drivers/../hosts,如果找到主机www.sohu.com对应的IP则访问该IP,如果未找到对应的IP,通过外网DNS查找;

b)   如果找到主机名对应的IP,发送http请求包;

c)    Apache解析http请求包:解析主机,解析站点名称,解析资源名称

d)    Apache发送回应包。

  1. Apache目录结构

bin:该目录用于存放apache常用的命令,比如httpd,apachemonitor

cgi-bin:该目录存放Linux下的常用命令.sh

conf:存放配置文件httpd.conf

error:错误记录

htdocs:存放我们的站点的文件夹(默认情况下),如果有多个站点,可以通过文件夹来分类

icons:存放图标

logs:记录apache的相关日志

manual:手册

 

特别注意:修改配置后要先stop服务,然后start,用restart起不到效果

  1. 修改默认站点目录(修改httpd.conf)

A)        修改DocumentRoot "D:/myblog"

B)        添加节点

<Directory "D:/myblog">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn\'t give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

 

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride None

 

    #

    # Controls who can get stuff from this server.

    #

    Order allow,deny

    Allow from all

 

</Directory>

 

 

  1. 添加虚拟目录()

作用:如果apache安装在c盘,但是c盘没有空间,d盘还有空间,能不能把d盘的一个文件夹下的网页html,php.当做管理。

a)    注释掉默认站点,否则apache会到默认文件中查找资源

#DocumentRoot "D:/workplace/phpEnv/apache/htdocs"

b)   添加虚拟目录节点

<IfModule dir_module>

 DirectoryIndex index.php

#设置别名

Alias /myblog "D:/myblog"

#把<Directory></Directory>看做配置的物理地址

<Directory "D:/myblog">

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* --- "Options All"

    # doesn\'t give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks

 

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride None

 

    #

    # Controls who can get stuff from this server.

    #设置权限

    Order allow,deny

    Allow from all

 

</Directory>

 

c)    访问:http://localhost/myblog

  1. 虚拟主机的配置(把虚拟目录当做是虚拟主机下的目录,如果没有配置虚拟主机,访问虚拟目录需要完整的地址http://localhost/myblog,现在以www.sohu.com打开)

a)    在httpd.conf中搜索Host,启用Include conf/extra/httpd-vhosts.conf

Include conf/extra/httpd-vhosts.conf

b)   配置hosts

127.0.0.1       www.sohu.com

c)    配置httpd-vhosts.conf

#配置我们自己的虚拟主机

<VirtualHost  127.0.0.1:80>

   

    DocumentRoot "D:/workplace/myblog"

    DirectoryIndex my.html index.php

    <Directory />

     Options FollowSymLinks

     #不允许别人对我的文件进行修改

     AllowOverride None

     Order allow,deny

     Allow from all

    

    </Directory>

 

</VirtualHost>

  1. 一台主机上配置多个虚拟主机,即一台主机绑定多个域名(如www.baidu.comwww.sohu.com访问本机不同的web站点)  (多个端口的配置?)

a)编辑c:\WINDOWS\system32\drivers\etc,添加:

127.0.0.1 www.a.com
127.0.0.1 www.b.com

b) 开启httpd.conf中Include conf/extra/httpd-vhosts.conf(注意这里是把http-vhosts.conf包含到httpd.conf文件中,其实把httpd-vhosts.conf中的配置写在httpd.conf中也可以),默认的httpd.conf默认网站配置将失效(也就是DocumentRoot "D:/myblog"会失效), 访问此IP的域名将全部指向 vhosts.conf 中的第一个虚拟主机.(相当于第一个虚拟主机是默认设置啦)

c)配置http-vhosts.conf,添加

  

<VirtualHost *:80>

DocumentRoot "D:/workplace/myblog2"

ServerName  www.a.com

</VirtualHost>

 

<Directory "D:/workplace/myblog2">

Options Indexes FollowSymLinks Includes ExecCGI

AllowOverride All

Order allow,deny

Allow from all

</Directory>

 

 

 

 

<VirtualHost *:80>

DocumentRoot "D:/workplace/myblog3"

ServerName  www.b.com

 

</VirtualHost>

 

<Directory "D:/workplace/myblog3">

Options Indexes FollowSymLinks Includes ExecCGI

AllowOverride All

Order allow,deny

Allow from all

</Directory>

 

 

<VirtualHost *:80>

DocumentRoot "D:/workplace/phpEnv/apache/htdocs"

ServerName localhost

</VirtualHost>

  1. 配置apache支持php

a) 下载php文件:一定要下载php-5.2.17-Win32-VC6-x86 (VC6表示用VC6编译的,不要下VC9的),不要下载php-5.2.17-nts-Win32-VC6-x86(nts表示not thread safe非线程安全)

b)将php.ini-recommended修改为:php.ini。查找php.ini中的extension_dir,设置为:

extension_dir = "D:/workplace/phpEnv/php/ext"

c)配置apache的httpd.conf,添加:

LoadModule php5_module "D:/workplace/phpEnv/php/php5apache2_2.dll"

#指定php.ini的目录

PHPIniDir  "D:/workplace/phpEnv/php/"

#这个配置表示,当有一个资源是*.php的时候就由php来处理

AddType application/x-httpd-php  .php

D)如果要支持mysql函数,需要在php.ini中启用php_mysql

;extension=php_mysql.dll

 

 

分类:

技术点:

相关文章: