Windows 下 PHP 7 安装配置
PHP 下载安装
PHP 下载地址:https://windows.php.net/download
关于版本选择,摘取官方说明:
Which version do I choose?
IIS
If you are using PHP as FastCGI with IIS you should use the Non-Thread Safe (NTS) versions of PHP.Apache
Please use the Apache builds provided by Apache Lounge. They provide VC14, VC15 and VS16 builds of Apache for x86 and x64. We use their binaries to build the Apache SAPIs.With Apache you have to use the Thread Safe (TS) versions of PHP.
VC14, VC15 & VS16
More recent versions of PHP are built with VC14, VC15 or VS16 (Visual Studio 2015, 2017 or 2019 compiler respectively) and include improvements in performance and stability.
- The VC14, VC15 and VS16 builds require to have the Visual C++ Redistributable for Visual Studio 2015-2019 x64 or x86 installed
大意就是IIS服务器选择Non Thread Safe版本,Apache服务器选择Thread Safe版本。
PHP配置
进入 PHP 安装目录,复制一份 php.ini-development 改名为 php.ini 放到安装路径下
找到
extension_dir,修改值为:PHP安装路径/ext在 Apache 中加载
PHP打开
conf\httpd.conf,找到LoadModule区域,在其后加入:1
2LoadModule php7_module "PHP安装路径\php7apache2_4.dll"
PHPIniDir "PHP安装路径"第一行在 Apache 中以
module的方式加载PHP,“php7_module” 中的 “7” 要和 PHP 的版本对应;此外,不同的 PHP 版本 “php7apache2_4.dll” 可能不同,在 php 根目录可以查看此文件。第二行告诉 Apache PHP 的安装路径
定义执行 PHP 模块的文件
查找
AddType application/x-gzip .gz .tgz,在其下一行添加代码:AddType application/x-httpd-php .php .html声明
.php和.html的文件能执行 PHP 程序测试 PHP 运行
在 Apache 服务器 web 目录下新建一个
test.php文件,内容:<?php phpinfo(); ?>重启 Apache 服务,浏览
localhost/test.phpMySQL 配置
打开
php.ini,将extension=mysqli取消注释。测试
编辑
test.php文件:1
<?php $mysqli = mysqli_connect("localhost","root","pwd") or die("cannt connet"); ?>
localhost数据库服务器名root数据库登录名pwd数据库登录密码启动
MySQL服务,如果没有报错则启动成功。



