参考文献:https://blog.csdn.net/blueheart20/article/details/76186218php
https://blog.csdn.net/phpservice/article/details/52727920html
http://www.jizhuomi.com/software/261.htmlmysql
https://blog.csdn.net/xujing19920814/article/details/52812849?locationNum=3&fps=1sql
一、下载Apache2.4(由于php7.0以上版本须要Apache2.4以上的支持),下载地址为http://www.apachehaus.com/cgi-bin/download.plx数据库
我下载的版本为:下图中最新2.4.33 x64:apache
三、下载php7.0(Microsoft Drivers for PHP for SQL Server驱动文件最新4.0支持到php7.0),下载地址:https://windows.php.net/download/windows
三、配置Apache和php浏览器
1)解压安装php7
将下载后的Apache解压缩。如解压到D:\php\Apache24。app
将下载的php-7.0.29-Win32-VC14-x64解压。如解压到D:\php\php-7.0.29-Win32-VC14-x64。
2)配置Apache24\conf下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:\php\php-7.0.29-Win32-VC14-x64\php.ini-production;复制并重命名为php.ini
(2)将 D:\php\php-7.0.29-Win32-VC14-x64和D:\php\php-7.0.29-Win32-VC14-x64\ext加入环境变量PATH中,
选中计算机,右键属性-->高级系 统设置 -->环境变量-->系统变量,找到Path,编辑,在其后加上; D:\php\php-7.0.29-Win32-VC14-x64;D:\php\php-7.0.29-Win32-VC14-x64\ext,下图,
(3)打开几个经常使用php扩展:
用记事本或其余编辑器打开D:\php\php-7.0.29-Win32-VC14-x64\php.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:\www\test.html, 添加内容为<?php phpinfo()?>,保存。
在浏览器中打开 127.0.0.1/test.html,是否是看到了phpinfo的相关内容,恭喜你,你的php已经跟apache协同工做了!
四、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:\php\php-7.0.29-Win32-VC14-x64 \ext。以下图所示:
2)php.ini修改
734行 extension_dir = "D:\php\php-7.0.29-Win32-VC14-x64\ext"
在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
五、安装sqlserver2008r2,安装教程:https://jingyan.baidu.com/article/0320e2c1286a2f1b87507b81.html
六、测试数据库链接
创建链接测试文件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