因为 PHP7 在 Windows 已经提供了完整的 64bit 支持,所以选择 64bit 系统安装 64bit PHP7 将获得更好的性能表现。
PHP7 需要 VC14 ( Visual C++ Redistributable for Visual Studio 2015 x86 or x64)做运行库,所以我们先要安装 VC14。
[b]一、下载并安装运行库:[/b]
x64 安装 64 位的运行库,x86 安装 32位的运行库。
[quote]
32位下载:[url=https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe]https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe[/url]
64位下载:[url=https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe]https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe[/url]
[/quote]
[img]http://files.jb51.net/file_images/article/201708/2017080522581913.png[/img]
[b]二、下载 PHP7[/b]
这里列出的是无安全线程的 PHP 7.0.3,其他版本大家可以到:[url=http://windows.php.net/download]PHP For Windows[/url] 查找。
[quote]
32位下载:[url=http://windows.php.net/downloads/releases/php-7.0.3-nts-Win32-VC14-x86.zip]http://windows.php.net/downloads/releases/php-7.0.3-nts-Win32-VC14-x86.zip[/url]
64位下载:[url=http://windows.php.net/downloads/releases/php-7.0.3-nts-Win32-VC14-x64.zip]http://windows.php.net/downloads/releases/php-7.0.3-nts-Win32-VC14-x64.zip[/url]
[/quote]
[b]三、解压并设置 PHP7[/b]
在 [code]C盘[/code] 创建 [code]php[/code] 目录。
[img] article=[/img]
让 Windows 显示文件后缀等, 点击 [code]查看[/code] —— [code]点勾如下图所示两项目[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522581916.png[/img]
复制 [code]php.ini-production[/code] 并改名为 [code]php.ini[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522581917.png[/img]
[img]http://files.jb51.net/file_images/article/201708/2017080522581918.png[/img]
②设置php时区
[code]date.timezone = Asia/Shanghai[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522581919.png[/img]
③开启php短标签
[code]short_open_tag 下的 `;` 全都删掉[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522581920.png[/img]
④以fast—CGI模式运行PHP
[code]cgi.force_redirect = 0[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522581921.png[/img]
[code]fastcgi.impersonate = 1[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522582622.png[/img]
[code]cgi.rfc2616_headers = 1[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522582623.png[/img]
⑤按需开启 PHP 模块
一般来说,GD、curl pdo_mysql 都是需要的
[img]http://files.jb51.net/file_images/article/201708/2017080522582624.png[/img]
[b]四、 检查是否正常运行[/b]
在 命令提示符(cmd) 中运行
[code]cd C:phpphp -v[/code]
如果然下图正常显示,那么就正常,如果有提示什么就按提示的修改
[img]http://files.jb51.net/file_images/article/201708/2017080522582625.png[/img]
[b]五、IIS 中设置 PHP[/b]
进入IIS控制面板选择主页,单击“处理程序映射”
[img]http://files.jb51.net/file_images/article/201708/2017080522582726.png[/img]
单击“添加模块映射”
[img]http://files.jb51.net/file_images/article/201708/2017080522582727.png[/img]
输入如下内容:
[quote]
请求路径:*.php
模块:FastCgiModule
可执行文件(可选):C:phpphp-cgi.exe
名称:FastCgi
[/quote]
如果没有 [code]FastCgiModule[/code] 模块,请确认之前再安装 IIS 的时候是否安装 CGI。
[img]http://files.jb51.net/file_images/article/201708/2017080522582728.png[/img]
单击“是”
[img]http://files.jb51.net/file_images/article/201708/2017080522582729.png[/img]
单击“FastCGI设置”
[img]http://files.jb51.net/file_images/article/201708/2017080522582730.png[/img]
按下图修改,将[code]监视对文件所做的更改[/code]改为 php.ini 文件所在的的绝对位置 [code]C:phpphp.ini[/code]
[img]http://files.jb51.net/file_images/article/201708/2017080522582731.png[/img]
在[code]聚合编辑器[/code]中添加:
[quote]
Name:PHP_FCGI_MAX_REQUESTS
Value:1000
[/quote]
[img]http://files.jb51.net/file_images/article/201708/2017080522582732.png[/img]
[img]http://files.jb51.net/file_images/article/201708/2017080522582733.png[/img]
5.在IIS控制面板中,单击“默认文档”,在默认的站点下新建一个名为“index.php”的文件
[img]http://files.jb51.net/file_images/article/201708/2017080522582734.png[/img]
[img]http://files.jb51.net/file_images/article/201708/2017080522582735.png[/img]
[b]六、试着运行 PHP 文档[/b]
将探针、phpinfo 加入你的站点目录中,查看运行:
[img]http://files.jb51.net/file_images/article/201708/2017080522582736.png[/img]
[img]http://files.jb51.net/file_images/article/201708/2017080522582837.png[/img]
[b]Windows Server 2016 服务器配置指南 之 开启 Zend OPcache 加速篇[/b]
Zend OPcache 是 PHP 的亲儿子字节码加速器,目前无论是兼容性还是性能都是最好的。尤其是在 PHP7 上,如果不开启 OPcache 真的在浪费资源啊~~
用记事本打开 php.ini,并增加以下内容:
[Zend OPcache]
zend_extension = php_opcache.dll
opcache.memory_consumption=128
opcache.optimization_level=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4096
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable=1
opcache.enable_cli=1
这里是推荐配置,有能力的可以根据 PHP 的官方文档进行针对化配置:[url=http://php.net/manual/zh/opcache.configuration.php]Zend Opcache 配置信息[/url]
然后保存,就 ok 了~
[img]http://files.jb51.net/file_images/article/201708/20170805231520.png[/img]