抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

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
    2
    LoadModule php7_module "PHP安装路径\php7apache2_4.dll"
    PHPIniDir "PHP安装路径"

    第一行在 Apache 中以 module 的方式加载 PHP ,“php7_module” 中的 “7” 要和 PHP 的版本对应;此外,不同的 PHP 版本 “php7apache2_4.dll” 可能不同,在 php 根目录可以查看此文件。

    第二行告诉 Apache PHP 的安装路径

    中文版 php.ini 说明

  • 定义执行 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.php

    MySQL 配置

    打开 php.ini ,将 extension=mysqli 取消注释。

    测试

    编辑 test.php 文件:

    1
    <?php  $mysqli = mysqli_connect("localhost","root","pwd") or die("cannt connet"); ?>

    localhost 数据库服务器名

    root 数据库登录名

    pwd 数据库登录密码

    启动 MySQL 服务,如果没有报错则启动成功。

评论