CakeFest 2024: The Official CakePHP Conference

在 Windows 上手动安装 PHP

选择 Web 服务器

IIS

IIS 是 Windows 内置的服务。在 Windows 服务器版本上,请使用服务器管理(Server Manager)来添加 IIS 规则。同时需要设置 CGI 角色规则。在 Windows 桌面版本上,需要使用控制面板中的 "添加/删除程序" 功能来添加 IIS。请参阅微软的官方文档的 » 详细说明。 对于桌面 web app 开发者,你也可以选择 IIS/Express 或 PHP Desktop。

示例 #1 命令行下配置 IIS 和 PHP


@echo off

REM download .ZIP file of PHP build from http://windows.php.net/downloads/

REM path to directory you decompressed PHP .ZIP file into (no trailing \)
set phppath=c:\php


REM Clear current PHP handlers
%windir%\system32\inetsrv\appcmd clear config /section:system.webServer/fastCGI
REM The following command will generate an error message if PHP is not installed. This can be ignored.
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /-[name='PHP_via_FastCGI']

REM Set up the PHP handler
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI /+[fullPath='%phppath%\php-cgi.exe']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /+[name='PHP_via_FastCGI',path='*.php',verb='*',modules='FastCgiModule',scriptProcessor='%phppath%\php-cgi.exe',resourceType='Unspecified']
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/handlers /accessPolicy:Read,Script

REM Configure FastCGI Variables
%windir%\system32\inetsrv\appcmd set config -section:system.webServer/fastCgi /[fullPath='%phppath%\php-cgi.exe'].instanceMaxRequests:10000
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phppath%\php-cgi.exe'].environmentVariables.[name='PHP_FCGI_MAX_REQUESTS',value='10000']"
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%phppath%\php-cgi.exe'].environmentVariables.[name='PHPRC',value='%phppath%\php.ini']"

Apache

有几个用于 Windows 的 Apache 版本。 推荐 ApacheLounge 编译的 Apache,但是其他选项(比如 XAMPP、 WampServer、 BitNami)提供了自动安装工具。 PHP 可以在带有 mod_php 或者 mod_fastcgi 的 Apache 上使用。 mod_php 需要使用相同版本的 Visual C 和 相同的 CPU (x86 或 x64) 编译的 Apache TS 版本。

选择编译版本

从 Windows 专用站点下载适合产品环境使用的 PHP 预编译版本: » http://windows.php.net/download/。 所有的编译都经过优化(PGO),并且 QA 和 GA版本都经过彻底测试。

PHP 编译版本有四种类型:

  • Thread-Safe(TS) - 线程安全,用于单进程 web 服务器,例如带有 mod_php 的 Apache

  • Non-Thread-Safe(NTS) - 非线程安全,用于 IIS 和其他 FastCGI web 服务器(使用带有 mod_fastcgi 的 Apache),并且推荐命令行脚本也用此版本

  • x86 - 用于 32 位系统。

  • x64 - 用于 64 位系统。

add a note

User Contributed Notes 1 note

up
-54
klaussantana at gmail dot com
3 years ago
If you're installing PHP 8.0.1 as Apache http server module, in httpd.conf you must use "php_module" in "LoadModule" directive instead of versioned names like in previous versions (aka, php5_module, php7_module, ...). Make the directive as follow:

LoadModule php_module "/path/to/php8apache2_4.dll"

I cracked my head over this...
To Top