首先在官網(wǎng)上下載Apache,安裝。安裝完后在安裝目錄下找到httpd文件,打開(kāi)httpd文件,找到:ServerName改為:localhost:80(根據(jù)實(shí)際情況改);改DocumentRoot "E:/Project/PHPProject"(根據(jù)實(shí)際項(xiàng)目所在目錄來(lái));改<Directory "E:/Project/PHPProject">(根據(jù)實(shí)際項(xiàng)目所在目錄來(lái));改DirectoryIndex index.php index.html(apache首頁(yè)默認(rèn)的文件,當(dāng)然你也可以定義更多,優(yōu)先查找前面的,沒(méi)有的話(huà)再查找后面的);改LoadModule php5_module "D:/php/php5apache2_4.dll"(php解壓后所在目錄下的php5apache2_4.dll文件路徑);改PHPIniDir "D:/php"(php解壓后的目錄);改AddType application/x-httpd-php .php .html .htm(讓apache支持php、html、htm三種格式,當(dāng)然你也可以定義更多格式);Apache配置完成。

第二步下載php,注意要下載Safe Thread版本的,Non Safe版本的里面沒(méi)有php5apache2_4.dll文件,我剛開(kāi)始下載錯(cuò)了,走了灣路。下載完后解壓。打開(kāi)解壓目錄,更改php.ini.develop為php.ini,打開(kāi)php.ini,將;extension=php_curl.dll的百分號(hào)去掉(其他一樣),改 extension_dir = "D:/PHP/ext";改date.timezone = Asia/Shanghai

第三步下載mysql,安裝后配置php.ini,放開(kāi)extension=php_mysqli.dll

訪問(wèn)mysql的代碼如下:

 

<?php
/* Connect to a MySQL server */
$link = mysqli_connect(
'localhost', /* The host to connect to */
'root', /* The user to connect as*/
'simon123', /* The password to use */
'jrdshop'); /* The default database to query */
if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}

/* Send a query to the server */
if ($result = mysqli_query($link, 'select * from userinfo')) {
printf("<table>");

/* Fetch the results of the query */
while( $row = mysqli_fetch_assoc($result) ){
printf("<tr><td>%s</td><td>%s</td></tr>",$row['UserID'], $row['UserName']);
}
/* Destroy the result set and free the memory used for it */
printf("<table>");
mysqli_free_result($result);
}
/* Close the connection*/
mysqli_close($link);
?>