Windows平台下PHP+Apache开发环境搭建方法备忘录

我使用的版本是:PHP5.3.24 + Apache Httpd 2.2.21,需要注意的是,Windows下的apache需要配合线程安全版本的PHP,在PHP官网下载时,需特别注意。比如PHP和Apache均安装在D盘根目录。

1、修改PHP配置文件:
1)将PHP安装目录中的php.ini-development改名为php.ini,并打开该文件
2)将extension_dir配置项修改为"D:/PHP/ext"
3)将doc_root配置项修改为"D:/Apache/htdocs"
4)将"extension=php_mysql.dll"前面的分号去掉,以支持MySQL数据库

2、修改Apache配置文件,搜索LoadModule,并在最后一个LoadModule后增加如下配置
LoadModule php5_module "D:/PHP/php5apache2_2.dll"
PHPIniDir "D:/PHP"
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html
3、启动Apache,在浏览器中输入http://127.0.0.1,如果提示"It Works",说明Apache的配置文件没有问题,但是否能够正确处理PHP呢?继续下一步尝试

4、在doc_root目录中创建一个测试文件test.php,调用phpinfo函数,然后在浏览器中输入http://127.0.0.1/test.php,如果能够正常打印出php的环境信息,说明PHP的配置也没有问题
<?php
    phpinfo();
?>
5、一般情况下,我都习惯把代码放在专门的项目目录,这就需要创建虚拟目录。在apache的httpd.conf的<IfModule alias_module>标签中增加这段,然后在浏览器中输入http://127.0.0.1/phptest/test.php,如果能够正常打印出php的环境信息,说明虚拟目录配置也没有问题
<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.bluerye.lab/bar
    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    Alias /phptest "D:/PHP Test Project"
    <Directory "D:/PHP Test Project">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client.  The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache/cgi-bin/"
</IfModule>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值