參考文獻:https://blog.csdn.net/blueheart20/article/details/76186218 https://blog.csdn.net/phpservice/article/details/52727920 http://www.jb51.net/article/ ...
參考文獻:https://blog.csdn.net/blueheart20/article/details/76186218
https://blog.csdn.net/phpservice/article/details/52727920
http://www.jb51.net/article/90056.htm
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:\php\Apache24。
將下載的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 去掉前面的分號
(4)測試:(大前提,Apache是開啟狀態)
編寫D:\www\test.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:\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
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的驅動程式,就直接複製報錯提示的鏈接下載驅動程式,並安裝
出現這個說明成功