欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

Windows下PHP+Apache2开发环境搭建

程序员文章站 2024-02-11 11:32:52
...
Windows下PHP+Apache2开发环境搭建

PHP线程安全与非线程安全版本选择 ####

参考:http://windows.php.net/download/

If you are using PHP as FastCGI with IIS you should use the Non-Thread Safe (NTS) versions of PHP
With Apache you have to use the Thread Safe (TS) versions of PHP.

结论:
+ IIS服务器:非线程安全的PHP版本
+ Apache服务器:线程安全的PHP版本

PHP下载

http://windows.php.net/download/
个人PC环境为:2位的win7,使用Apache服务器。
所以下载目前最新版本:
PHP 5.6 (5.6.9)的“VC11 x86 Thread Safe (2015-May-14 18:29:57)”的压缩包

Apache下载

http://www.apachelounge.com/download/
目前最新的为:Apache 2.4.12 Win32

PHP+Apache的配置

参考:http://php.net/manual/zh/install.windows.apache2.php

修改Apache的基本配置信息

在{apache}/conf/httpd.conf中修改 ServerRoot 和 DocumentRoot 的路径:

#服务器文件路径
ServerRoot "c:/bin/Apache24"
#项目文件路径
DocumentRoot "c:/bin/htdocs"

#   ...

以Apache handler方式安装

在{apache_path}/conf/httpd.conf中添加如下信息:

# 以Apache handler方式安装运行PHP
LoadModule php5_module "C:/bin/php5.6/php5apache2_4.dll"

    AddHandler application/x-httpd-php .php

    # 配置 php.ini 的路径
    PHPIniDir "C:/bin/php5.6"

    # 配置处理文件的格式
    
        SetHandler application/x-httpd-php
    

以Apache handler方式安装

下载fast-cgi模块:http://www.apachelounge.com/download/win32/
解压到apche的modules目录中。

在 {apache_path}/conf/httpd.conf 中添加如下fast-cgi的配置信息:

# 加载fast-cgi模块
LoadModule fcgid_module modules/mod_fcgid.so
# fast-cgi模块配置
 
    # Where is your php.ini file?
    FcgidInitialEnv PHPRC "c:/bin/php5.6/" 
    FcgidInitialEnv PATH "C:/bin/php5.6;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;" 
    FcgidInitialEnv SystemRoot "C:/Windows" 
    FcgidInitialEnv SystemDrive "C:" 
    FcgidInitialEnv TEMP "C:/WINDOWS/TEMP" 
    FcgidInitialEnv TMP "C:/WINDOWS/TEMP" 
    FcgidInitialEnv windir "C:/WINDOWS" 

    FcgidIOTimeout 40
    FcgidConnectTimeout 10 
    FcgidMaxProcesses 1000 
    FcgidOutputBufferSize 64 
    FcgidProcessLifeTime 120 
    FcgidMaxRequestsPerProcess 10000 
    FcgidMinProcessesPerClass 0 
    FcgidFixPathinfo 1 

    # Global Config Example 
     
        Options Indexes FollowSymLinks ExecCGI 
        AddHandler fcgid-script .php 

        FcgidWrapper "c:/bin/php5.6/php-cgi.exe" .php 
    

下载的fast-cgi模块压缩包中readme.txt有详细的配置信息

启动Apache服务器

在cmd命令行中执行 {apache_path}/bin/httpd.exe 即可

在phpinfo()中,通过phpinfo()的”Server API”的值判断运行模式:

  • CGI/FastCGI : Fast-cg模式
  • Apache 2.0 Handler : Apache handler模式

若在httpd.cnf中对apache hanlder和fast-cgi都进行了配置,则使用apache handler模式

以上就介绍了Windows下PHP+Apache2开发环境搭建,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。