WindowsでNginxを構築します
最近はNginxが流行ってきているということで、Windowsでやってる方が少ないのもあって構築方法をメモメモ
Windows + Nginx + FastCGI + PHP + Mysql の組み合わせで WordPress が動作するところまでです
検証環境は Windows7x64 です
ダウンロード
必要なものを集めてきます。
Nginx → Stable Version nginx/Windows-1.0.12
PHP → PHP5.3 VC9 x86 Non Thread Safe
Mysql → MySQL Community Server 5.5.20 Windows (x86, 32-bit), MSI Installer
Wordpress → WordPress 3.3.1
解凍
NginxをC:\Program Files\nginx-1.0.12 に解凍
PHPを C:\Program Files\php-5.3.10-nts-Win32-VC9-x86 に解凍
Wordpressを C:\www に解凍
Mysqlをインストール。(ry
動作確認
1. まずNginxの動作確認。
“C:\Program Files\nginx-1.0.12\nginx.exe” を起動してから、ブラウザで localhost に接続する。
「 Welcome to nginx! 」と表示されればOK
2. 次にPHPの動作確認
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 の項目のコメントアウトを外して次のようにする
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; }
“C:\Program Files\php-5.3.10-nts-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9000” で PHPを起動し、
“C:\Program Files\nginx-1.0.12\nginx.exe -s reload” で変更した設定を読み込む。
ブラウザで localhost/tekitou.php にアクセスします。
「 No input file specified. 」と表示されれば、Nginx PHP 間のやり取りは成功です
WordPressを動かす
“C:\Program Files\nginx-1.0.12\conf\nginx.conf” の
location / { root html; index index.html index.htm; }
を以下のようにする
location / { root C:/WWW; index index.php index.html index.htm; }
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 の項目を
location ~ \.php$ { root C:/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME C:/WWW$fastcgi_script_name; include fastcgi_params; }
にする。
“C:\Program Files\php-5.3.10-nts-Win32-VC9-x86\php.ini-production” を コピーして php.ini を作成する
そして php.ini の
;extension=php_mysql.dll のコメントアウトを解除して
extension=php_mysql.dllにする
phpを再起動する。
ブラウザで localhost に接続する
自動起動するようにする
ポートを介してphpを利用するためIISやApacheと違って事前にphpを起動させておく必要があります。
batファイルを作って起動時に実行させます
start C:\"Program Files"\php-5.3.10-nts-Win32-VC9-x86\php-cgi.exe -b 127.0.0.1:9000 start C:\"Program Files"\nginx-1.0.12\nginx.exe
参考サイト
nginx + PHP on Windows in 5 minutes
Install WordPress on WEMP (Windows, nginx, MySQL and PHP)
nginxの起動オプション
CGI版のPHPで「No input file specified.」のエラーを解決する方法
fastcgi_param SCRIPT_FILENAME パラメータの意味
WordPressを100倍速くする! MySQLの調整やnginx proxy cache
ソースファイルが shift-jis だと文字化けする問題 「未解決」