在Windows 云服务器中进行 PHP 配置,需要完成 IIS 角色的添加和安装,详细请见我的上一篇文章安装配置IIS+MySQL+PHP环境的详细教程之篇一IIS安装.
本文介绍PHP 5.3 之后版本,php7X的安装
PHP 5.3 版本后取消了安装包模式,仅通过 zip 文件和 debug pack 两种方式进行安装。本例使用 Windows Server 2012 R2 环境下 zip 安装进行示例。
下载PHP zip包
1、在云服务器中下载 PHP zip 安装包(下载地址: http://windows.php.net/download/ )。
注意:在 IIS 下运行时必须选择 Non Thread Safe(NTS) 的 x86 包。若一定要在 Windows Server 32bit (x64) 下,PHP 选择 x64,则不能选择 IIS,此时可使用 Apache 作为代替选项。
选择类似如下的安装包:


安装Visual C++ Redistributable Update依赖包
2、PHP 5.3 以上版本的安装依赖于 Visual C++ Redistributable Update 。请根据下载的 PHP 安装包名,参考如下表格所示的对应关系下载并安装 VC Update 安装程序:
PHP安装包名 | Visual C++ Redistributable安装包下载地址 |
php-x.x.x-nts-Win32-VC15-x86.zip | https://www.microsoft.com/zh-cn/download/details.aspx?id=48145 |
php-x.x.x-nts-Win32-VC11-x86.zip | https://www.microsoft.com/zh-cn/download/details.aspx?id=30679 |
php-x.x.x-nts-Win32-VC9-x86.zip | https://www.microsoft.com/zh-cn/download/details.aspx?id=5582 |
若下载的 PHP 安装包如下图所示:

则按表格第一行对应关系下载 VS 2015 版本的安装包,下载并安装如下两个.exe格式文件:

解压并设置PHP、配置php.ini
将 PHP zip 安装包解压(本例解压至 C:\PHP),复制php.ini-production并改名为php.ini,如下图所示:

配置IIS,让其支持.php
单击【服务器管理器】-【IIS】,在本地 IIS 上右键单击选择 IIS 管理器:

单击左侧 主机名(IP) 来到主页,双击【处理程序映射】:

单击右侧【添加模块映射】按钮,在弹出框中填写如下信息并单击【确定】按钮保存:

注意: 若可执行文件选择不了 php-cgi.exe ,请文件后缀变为.exe:

单击左侧 主机名(IP) 回到主页,双击【默认文档】:

单击右侧【添加】按钮,添加名称为index.php的默认文档:

单击左侧主机名(IP)回到主页,双击【 FastCGI 设置】:

单击右侧【编辑】按钮,在【监视对文件所做的更改】中选择 php.ini 路径:


确认环境已支持PHP
在 C:\inetpub\wwwroot 目录下创建一个PHP文件 index.php ,写入如下内容:
<?php phpinfo();
在云服务器打开浏览器内访问 http://localhost/index.php ,查看环境配置是否成功。如果页面可以显示如下,说明配置成功:
