[Windows] 自己打造綠色或稱可擕式(portable)的WNMP - Nginx+PHP5+MySQL(Mari

回覆文章
yehlu
Site Admin
文章: 3244
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

[Windows] 自己打造綠色或稱可擕式(portable)的WNMP - Nginx+PHP5+MySQL(Mari

文章 yehlu »

http://web.dhjh.tc.edu.tw/~gzqbyr/fluxb ... php?id=305

可擕式(portable) WAMP,參考 http://web.dhjh.tc.edu.tw/~gzqbyr/fluxb … php?id=377
安裝前須知
VC9 與 VC11(原文請請參考http://windows.php.net/download/)
使用 VC9 版本時,需安裝 Visual C++ Redistributable for Visual Studio 2008 SP1 x86 or x64。
使用 VC11 版本時,需安裝 Visual C++ Redistributable for Visual Studio 2012 x86 or x64。
註:x86 表示 32位元版本,x64 表示 64位元版本。
因為 PHP 5.5.x 不支援 Windows XP 與 Windows 2003,因此本文僅介紹 PHP 5.4.x。如果你的 Windows 作業系統夠新,當然就可用 PHP 5.5.x 取代 PHP 5.4.x。
先提供我製作的可擕式(portable) WNMP Lite
下載 WNMP-Lite-Win32-VC9-portable.7z 解壓縮至 D:\ (也可解壓縮至 C:\)。解壓縮後大約42M,因為PHP、MariaDB經過瘦身,有完整版需求者請自行至相關官網下載,覆蓋檔案即可。此版本已設定使用者目錄(UserDir),欲安裝 WordPress 參考 http://web.dhjh.tc.edu.tw/~gzqbyr/fluxb … php?id=382。
執行 D:\WNMP\start.bat 即可啟動網頁伺服器,而執行 D:\WNMP\stop.bat 可停止伺服器。
瀏覽 127.0.0.1/adminer.php,帳號 輸入 root ⇨ 登入。
wnmp09.png
開始製作可擕式 WNMP
建立 D:\WNMP 資料夾。
Nginx 安裝:
http://nginx.org/en/download.html 下載 nginx-1.4.x(x 表示版本號),解壓縮至 D:\WNMP。將 D:\WNMP\nginx-1.4.7 重新命名為 D:\WNMP\nginx。
編輯 nginx\conf\nginx.conf
尋找
location / {
root html;
index index.html index.htm;
}
取代為
location / {
root html;
index index.php index.html index.htm;
}

location ~ .*\.php(\/.*)*$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
PHP 安裝:
建立資料夾 D:\WNMP\php。
http://windows.php.net/downloads/releases/archives/ 下載 php-5.4.x-Win32-VC9-x86.zip(x 表示版本號),解壓縮至 D:\WNMP\php。(僅php5.2才能使用SQLite2)
重新命名 D:\WNMP\php\php.ini-development 為 php.ini
編輯 D:\WNMP\php\php.ini(不同的PHP版本的 extension 設定也稍微不一樣)
尋找
; extension_dir = "ext"
取代為
extension_dir = "./ext/"
尋找
;date.timezone =
取代為
date.timezone = "Asia/Taipei"
尋找
;extension=php_gd2.dll
;extension=php_mbstring.dll
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=php_pdo_mysql.dll
;extension=php_pdo_sqlite.dll
;extension=php_sqlite3.dll
取消註解 ;。
MariaDB 安裝:(以MariaDB取代MySQL)
MariaDB 官網 - https://mariadb.org/
以 MariaDB-5.5.36 為例。
https://downloads.mariadb.org/mariadb/5.5.36/ 下載 mariadb-5.5.36-win32.zip,解壓縮至 D:\WNMP。
至 D:\WNMP 將 資料夾 mariadb-5.5.36-win32 更名為 mariadb
下載 NirCmd,解壓縮後將 nircmd.exe 複製至 D:\WNMP。
將 restart.bat、start.bat、stop.bat 存至 D:\WNMP。
restart.bat
@echo off
call stop.bat
call start.bat
start.bat
@echo off
nircmd exec hide "php\php-cgi.exe" -b 127.0.0.1:9000 -c php\php.ini
:startnginx
cd nginx
..\nircmd exec hide "nginx.exe" -c conf\nginx.conf
cd ..
:mariadb
nircmd exec hide "mariadb\bin\mysqld.exe"
stop.bat
@echo off
taskkill /F /IM mysqld.exe > nul
taskkill /F /IM nginx.exe > nul
taskkill /F /IM php-cgi.exe > nul
執行 D:\WNMP\start.bat 即可啟動網頁伺服器,而執行 D:\WNMP\stop.bat 可停止伺服器。
下載 Adminer 至 D:\WNMP\Apache24\htdocs\ 並重新命名為 adminer.php
瀏覽 127.0.0.1/adminer.php,帳號 輸入 root ⇨ 登入。
wnmp09.png
關於 MariaDB 的 root 密碼:
設定 root 密碼為 123456
<?php
mysql_connect("localhost","root","");
$sql="set password for root@localhost=password('123456')";
mysql_query($sql);
?>
建立資料庫db1,增加 MariaDB 使用者user密碼userpw 及擁有資料庫db1的全部權限
<?php
$rootpw = "123456"; //Note: 你的 root 密碼也是 123456?
$link = mysql_connect("localhost","root",$rootpw);
$sql="CREATE DATABASE db1";
mysql_query($sql);
$sql="grant all on db1.* to user@localhost identified by 'userpw'";
mysql_query($sql);
?>
瀏覽 127.0.0.1/adminer.php,帳號輸入 user,密碼輸入 userpw ⇨ 登入。
設定使用者目錄(UserDir):
建立資料夾 D:\home\bob\www
編輯 nginx\conf\nginx.conf
尋找
location ~ .*\.php(\/.*)*$ {
之前加入
location ~ ^/~(?<userdir_user>.+?)(?<userdir_uri>/.*)?$ {
alias /home/$userdir_user/www$userdir_uri;
index index.php index.html index.htm;
autoindex on;

location ~ .*\.php(\/.*)*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
執行 D:\WNMP\restart.bat。瀏覽 127.0.0.1/~bob/
CRLin於免費空間安裝的 FluxBB
http://fluxbbtw.heliohost.org (SQLite)
http://fluxbb.freevar.com
回覆文章

回到「PHP」