Windows之安裝Nginx、PHP、mysql

說明

由於機器本身是Windows x64系統,所以選擇了所有x64的軟件;如果想選擇x86也可以兼容;如果機器是x86的,那麼只能選擇x86的軟件

下載地址

安裝配置 nginxphp

安裝 nginx

  1. 選擇軟件安裝目錄爲 c:\zjc - 這個目錄可以更改
  2. 解壓 nginx-1.9.4.zipc:\zjc\server\nginx
  3. c:\zjc\www 作爲網站根目錄
    1. 修改配置文件 c:\zjc\server\nginx\conf\nginx.conf
    2. location / 節點下面的 root 修改爲 root c:\zjc\www
    3. c:\zjc\www 目錄下創建測試網頁 index.html
  4. 雙擊運行 :\zjc\server\nginx\nginx.exe, 瀏覽器打開 http://127.0.0.1,可以看到剛纔創建的網頁
  5. 可以停止 nginx
    cd c:\zjc\server\nginx
    nginx.exe -s stop

安裝 php

  1. 解壓 php-5.6.12-nts-Win32-VC11-x64.zipc:\zjc\server\php
  2. c:\zjc\server\php\php.ini-development 改名爲 php.ini

安裝 vcredist_x64.exe

點擊安裝就好了

安裝 RunHiddenConsole

  1. RunHiddenConsole.zip 包中的 RunHiddenConsole.exe 解壓到 c:\zjc\server\utils 目錄

配置 nginxphp

修改 c:\zjc\server\nginx\conf\nginx.conf

修改

    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    location ~ \.php$ {
    #    root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  c:/zjc/www$fastcgi_script_name;
        include        fastcgi_params;
    }

啓動停止腳本

  • c:\zjc\svr_start.bat
    內容爲
cd server\php
..\utils\RunHiddenConsole.exe php-cgi.exe -b 127.0.0.1:9000 -c c:/zjc/server/php/php.ini
cd ..\..
cd server\nginx
..\utils\RunHiddenConsole.exe nginx.exe
cd ..\..
  • c:\zjc\svr_stop.bat
    內容爲
taskkill /F /IM nginx.exe > nul
taskkill /F /IM php-cgi.exe > nul

測試 nginxphp

創建文件 c:\zjc\www\index.php , 內容爲

<?php
echo phpinfo();
?>

訪問 http://127.0.0.1/index.php , 可以看到 php 相關的信息就對了

安裝配置 mysql

  1. 運行 dotNetFx40_Full_x86_x64.exe
  2. 運行 mysql-installer-community-5.6.26.0.msi
    • 選擇 Server Only
  3. 修改 c:\zjc\server\php\php.ini 來開啓 phpmysql 的支持
    extension_dir = "ext"
    extension=php_mysqli.dll

測試 nginxphpmysql

新建網頁

c:\zjc\www\check_mysql.php
內容爲

<?php
$con = mysqli_connect("localhost", "root", "a123456");
if(!$con) {
    die('Could not connect: ' . mysqli_error());
} else {
    echo "Database connected successfully";
}
mysqli_close($con);

重啓服務器

$ c:
$ cd c:\zjc
$ svr_stop.bat
$ svr_start.bat

訪問網頁 http://127.0.0.1/check_mysql.php

可以看到連接成功的消息就對了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章