参考文献:https://blog.csdn.net/blueheart20/article/details/76186218

                 https://blog.csdn.net/phpservice/article/details/52727920

                 http://www.jizhuomi.com/software/261.html

                 https://blog.csdn.net/xujing19920814/article/details/52812849?locationNum=3&fps=1

 1、下载Apache2.4(因为php7.0以上版本需要Apache2.4以上的支持),下载地址为http://www.apachehaus.com/cgi-bin/download.plx

我下载的版本为:下图中最新2.4.33 x64:

3、下载php7.0(Microsoft Drivers for PHP for SQL Server驱动文件最新4.0支持到php7.0),下载地址:https://windows.php.net/download/

 3、配置Apache和php

1)解压安装

       将下载后的Apache解压缩。如解压到D:phpApache24。

       将下载的php-7.0.29-Win32-VC14-x64解压。如解压到D:phpphp-7.0.29-Win32-VC14-x64。

 2)配置Apache24conf下httpd.conf 文件,用记事本打开即可:

      (1)第38行SRVROOT值改为 "D:/php/Apache24"//Apache程序的位置。   

               这里定义了变量,以后用到的SRVROOT都是这个路径 

      (2)第213行ServerName前面的“#”号去掉;     

      (3)第246行DocumentRoot "c:/Apache24/htdocs"改为DocumentRoot "D:/www";//网站的根目录

               第247行<Directory"c:/Apache24/htdocs">改为<Directory "D:/www ">;

               注意:这个WWW文件夹要自己去新建的,不建的话会报错的。

      (4)第281行DirectoryIndex index.html改为DirectoryIndexindex.html index.php index.htm   //支持更多的默认页

      (5)文件添加下面几行,增加对php7的支持:

               PHPIniDir "D:/php/php-7.0.29-Win32-VC14-x64"

               LoadModule php7_module "D:/php/php-7.0.29-Win32-VC14-x64/php7apache2_4.dll"

               AddType application/x-httpd-php .php .html .htm

      (6)测试。把index.html(内容随便写的什么)放到D:www目录下,用浏览器,地址栏输入localhost,访问会出现index.html文件内的内容,Apache配置成功。

 

3)配置php

    (1)打开D:phpphp-7.0.29-Win32-VC14-x64php.ini-production;复制并重命名为php.ini

    (2)将 D:phpphp-7.0.29-Win32-VC14-x64和D:phpphp-7.0.29-Win32-VC14-x64ext加入环境变量PATH中,

             选中计算机,右键属性-->高级系 统设置 -->环境变量-->系统变量,找到Path,编辑,在其后加上; D:phpphp-7.0.29-Win32-VC14-x64;D:phpphp-7.0.29-Win32-VC14-x64ext,下图,

      (3)打开几个常用php扩展:

               用记事本或其他编辑器打开D:phpphp-7.0.29-Win32-VC14-x64php.ini

               ;extension_dir = "ext"修改为 extension_dir = "ext" (去掉extension前面的分号)

               893行 ;extension=php_curl.dll 去掉前面的分号

               896行 ;extension=php_gd2.dll 去掉前面的分号

               903行 ;extension=php_mbstring.dll 去掉前面的分号

               905行 ;extension=php_mysqli.dll 去掉前面的分号

               909行 ; extension=php_pdo_mysql.dll 去掉前面的分号

       1040行

     [SQL]

     ; http://php.net/sql.safe-mode

     sql.safe_mode = On

    462行    display_errors = On  用来显示错误信息

       (4)测试:(大前提,Apache是开启状态)

               编写D:wwwtest.html, 添加内容为<?php phpinfo()?>,保存。

               在浏览器中打开 127.0.0.1/test.html,是不是看到了phpinfo的相关内容,恭喜你,你的php已经跟apache协同工作了!

              

 

4、php与sql server 连接测试

       1)下载驱动Microsoft Drivers for PHP for SQL Server,下载地址:http://www.microsoft.com/en-us/download/details.aspx?id=20098    

                下载链接地址有四个文件:

                •SQLSRV30.EXE

                •SQLSRV31.EXE

                •SQLSRV32.EXE

                •SQLSRV40.EXE

                分别支持不同的PHp版本

                •Version 4.0 supports PHP 7.0+

                •Version 3.2 supports PHP 5.6, 5.5, and 5.4

                •Version 3.1 supports PHP 5.5 and 5.4

                •Version 3.0 supports PHP 5.4.

               因为我安装的是PHP7.0版本,所以下载的是SQLSRV40.EXE

               安装SQLSRV40.EXE,选择解压路径为:D:phpphp-7.0.29-Win32-VC14-x64 ext。如下图所示:

              

   2)php.ini修改

            734行 extension_dir = "D:phpphp-7.0.29-Win32-VC14-x64ext"

            在php.ini 里加上以下三句:

           extension=php_odbc.dll

           extension=php_sqlsrv_7_ts_x64.dll

          extension=php_pdo_sqlsrv_7_ts_x64.dll

   3)保存php.ini,重启apache,浏览器打开127.0.0.1/test.html

   

5、安装sqlserver2008r2,安装教程:https://jingyan.baidu.com/article/0320e2c1286a2f1b87507b81.html

6、测试数据库连接

       建立连接测试文件test.php   

      <?php

           header("Content-type: text/html; charset=utf-8");

           $serverName = "localhost";

           //数据库名字叫test

           $connectionInfo =array("Database"=>"test","UID"=>"sa","PWD"=>"root");

           $conn = sqlsrv_connect($serverName, $connectionInfo );

           if( $conn === false ) {

               die( print_r( sqlsrv_errors(), true));

                }else{
               echo "连接数据库正确";
           }

      ?>

刚开始页面出现报错,rray ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712[message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 [message] => [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 ) )

是因为没有安装ODBC的驱动程序,就直接复制报错提示的链接下载驱动程序,并安装

出现这个说明成功

 

7.安装mysql

文献:https://www.cnblogs.com/fenliar-zss/p/6896704.html

      https://jingyan.baidu.com/article/a3f121e4a6eb67fc9052bbf4.html

8.安装phpmyadmin

 文献:https://blog.csdn.net/yangchen9931/article/details/52881797

 

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!