nginx+php-cgi+mysqlのお手軽起動環境を作成する(Windows)

WindowsでPHPの開発環境を手軽に構築します。
nginx + MySQL + PHPの環境をバッチファイル一つで起動・停止を行えるように設定して、
コピーするだけで他マシンにも環境を移せるのがメリットです。

ダウンロードするもの

ダウンロードしたファイルをすべて解凍して、nginxへ放りこんでcドライブ直下へ放り投げます。

nginx設定

c:\nginx\conf\nginx.conf



公開ディレクトリ設定

location / { root c:/nginx/html; index index.php index.html index.htm; } ... ..(省略) ..

PHP設定

location ~ .php$ { root c:/nginx/html; fastcgi_pass localhost:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME c:/nginx/html$fastcgi_script_name; include fastcgi_params; }

サーバ一括起動バッチを作成

c:\nginxの中にstart.batを作成


@ECHO OFF
start c:\nginx\nginx.exe
start /b c:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini
start C:\nginx\mysql\bin\mysqld.exe

echo Starting nginx php-cgi mysql
echo .

コマンドプロンプト窓が出ている間サーバが起動した状態になります。

サーバ一括停止バッチ作成

c:\nginxの中にstop.batを作成


@ECHO OFF
c:\nginx\nginx.exe -s quit
taskkill /f /IM nginx.exe
taskkill /f /IM php-cgi.exe
c:\nginx\mysql\bin\mysqladmin shutdown -u root

start.bat, stop.batだけでwebサーバ+MySQLが全てコントロールできます。

サーバアクセス

c:\nginx\html にindex.phpをおいてみます。

<?php
// (index.php)
phpinfo();

http://localhost/ レッツアクセス

他のPCに環境を持って行く場合は、
cドライブの直下にnginxディレクトリごとコピーしてください。

参考

無職のプログラミング : nginx for Windows でPHPを動かす
http://himaxoff.blog111.fc2.com/blog-entry-63.html