edo1z blog

プログラミングなどに関するブログです

nginxでphpを使う(CentOS6.5)

参考:Nginx でPHPを動かす(php-fpmをインストールする) [PHP5.3以降の場合]

PHPをFastCGI化する必要があります。 php5.3がインストールされている場合、 yum php-fpmとやると、php-fpmがインストールできます。

vim /etc/php-fpm.d/www.conf ここにuserとかgroupがapacheになっているので、nginxに変更します。 ちなみに、/etc/php-fpm.confがphp-fpmの基本設定ファイルになります。

vim /etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  localhost;

    charset utf-8;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }
}

service php-fpm restart service nginx restart