More Related Content
Similar to Webサーバ勉強会4 nginx で php-fpm を動かしてみた (20)
Webサーバ勉強会4 nginx で php-fpm を動かしてみた
- 2. do_aki (どぅーあき)
• |所属| > 株式会社もしも
(ドロップシッピング・アフィリエイトASP)
• |仕事| > インフラ構築・運用 兼
Webアプリケーション開発・運用
• |出現| > 渋谷・山手線沿線
• |特性| > PHPer
http://do-aki.net/
- 4. 自分の nginx の認識
• 今まで動かしたこと無かった
• 軽快・設定がシンプル
• シングルスレッド
• イベント駆動的な?
程度の知識しか持ってない
- 7. 環境
• Scientific Linux 6.0
• nginx version 1.0.9 (latest stable)
• PHP version 5.4.0 beta2
(昨日 RC1でちゃったケド)
- 8. 最初に configure
./configure
--prefix=/usr
--sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid
--lock-path=/var/lock/nginx.lock
--user=nginx --group=nginx
--with-http_ssl_module --with-http_flv_module
--with-http_gzip_static_module
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/run/nginx/client/
--http-proxy-temp-path=/var/run/nginx/proxy/
--http-fastcgi-temp-path=/var/run/nginx/fcgi/
--http-uwsgi-temp-path=/var/run/nginx/uwsgi/
--http-scgi-temp-path=/var/run/nginx/scgi/
あらかじめ pcre-devel パッケージをインストール (たぶん openssl-devel zlib-devel)
- 9. とりあえず試す
• make & make install
• $ sudo /usr/sbin/nginx
• t オプションで設定ファイルチェック
• SIGHUP 送ると設定再読み込み
ドキュメント結構しっかりしてるね!
- 10. ドキュメントルートが分からず
基準パスはどこ?
location / {
root html;
index index.html index.htm;
}
- 11. ドキュメントルートが分からず
絶対パスなら確実
location / {
root /var/www/html;
index index.html index.htm;
}
- 12. server {
listen 8888; nginx.conf 80から変更
server_name localhost;
location / {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php; fastcgi 用設定
include /etc/nginx/fastcgi.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 13. 一方 php-fpm
./configure
--cache-file=./config.cache
--with-layout=GNU
--disable-debug
--disable-rpath
--enable-zip
--enable-mbstring=ja
--enable-mbregex
--with-openssl
--with-zlib
--enable-ftp
--enable-sockets
--enable-sysvsem --enable-sysvshm --enable-sysvmsg
--with-apxs2=/usr/sbin/apxs
--enable-fpm
- 14. php-fpm を実行
• make & make install
• sudo /usr/local/sbin/php-fpm
• default port は 9000
• make install しなくても、設定ファイルさえ正
しい場所に置いておけば動く
• php-5.4.0beta2/sapi/fpm/php-fpm を実行でも
可能 (設定ファイルの場所はエラーで表示)
- 17. Fastcgi.conf
(あるいはfastcgi_params)
fastcgi_param SERVER_NAME $server_name;
server_name localhost;
- 18. server {
listen 8888; nginx.conf
server_name 192.168.29.128;
location / {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /etc/nginx/fastcgi.conf;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 19. まとめ
• nginx × php-fpm あっさり動いちゃった
• むしろ、チューニンガソン2で動かなかった
理由は何だったんだ……?
• 当時は aplha3 だったから?
• モジュールによって?
• php-fpm は EXPERIMENTAL なので、プロダク
ションでは使わないようにね!