Nginx - PHPを動作させる : PHP-FPM2013/07/07 |
|
Nginx で PHP が動作するよう設定します。
Nginx と PHP は別プロセスで動作するため、間を取り持つモジュールが必要になります。 ここでは、PHP-FPM ( PHP FastCGI Process Manager ) を使って実装してみることにします。 |
|
| [1] | PHP & PHP-FPM インストール |
|
[root@www ~]# yum --enablerepo=epel -y install php php-mbstring php-pear php-fpm # EPELからインストール
|
| [2] | PHP-FPM の設定 |
|
[root@www ~]#
vi /etc/php-fpm.d/www.conf # 39行目:変更 user = nginx # 41行目:変更 group = nginx
[root@www ~]#
/etc/rc.d/init.d/php-fpm start Starting php-fpm: [ OK ] [root@www ~]# chkconfig php-fpm on
[root@www ~]#
vi /etc/nginx/conf.d/default.conf # server セクション内の適当な位置に設定を追記
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
/etc/rc.d/init.d/nginx restart Stopping nginx: [ OK ] Starting nginx: [ OK ] |
| [3] | PHPInfo を作成して PHP の動作確認をしてください。以下のようなページが表示されればOKです。 |
|
[root@www ~]# echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php |
|
| Sponsored Link |
|
|