php5.3+apache2.2配置要点

来源:互联网 发布:软件编程是什么 编辑:程序博客网 时间:2024/06/04 00:05

1 找到apache下的conf/httpd.ini

(1)设置DocumentRoot

DocumentRoot = "D:/php5"(你的php开发项目所在目录)

(2)设置Directory 

<Directory "D:/php5">
    #
    # 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>


(3)#此处用于设置默认的主页,以及有限顺序

<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

(4)找到LoadModule 所在位置,添加如下内容

LoadModule php5_module "D:/Program Files/php-5.3.5-Win32-VC6-x86/php5apache2_2.dll" #加载php对apache的支持文件
PHPIniDir "D:/Program Files/php-5.3.5-Win32-VC6-x86"  #php.ini文件所在位置
AddType application/x-httpd-php .php .html .htm  #apache下,php识别的文件类型

LoadModule rewrite_module modules/mod_rewrite.so  #添加apache对页面重定向的支持

(5)其它优化设置的等你的水平高了,可以慢慢来。

(6)为了支持重定向,你需要在你的项目文件目录下,添加文件  【.htaccess】。内容如下

<IfModule mod_rewrite.c>
    RewriteEngine On


    # 如果访问的文件存在,则直接访问,不重定向
    RewriteCond %{REQUEST_FILENAME} !-f
    # 如果访问的目录存在,则直接访问,不重定向
    RewriteCond %{REQUEST_FILENAME} !-d


    # 如果访问的文件或目录不存在,则重定向所有请求
    # 到:index.php?url=<PARAMS>。
    # 例如:当我们请求<域名>item/index时,实际上是
    # 请求<域名>index.php?url=item/index,在PHP中
    # 用 GET['url'] 就能拿到字符串item/index
    RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>

(7)我的数据库使用odbc方式,所以不用任何配置即可使用数据库

好了,如果顺利的话,你在 项目根目录下新建 index.php 内容如下

<?php

phpinfo();

?>

在浏览器输入 localhost/web 即可看到 很长的php相关信息。(注web是我的php开发项目名)