2014年2月3日月曜日

nginx+php

nginx入れたメモ

nginx公式リポジトリを入れる
# wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
# rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

nginxインストール
# yum install -y nginx

起動、自動起動設定
# service nginx start
# chkconfig nginx on

wwwグループ、wwwユーザー作成、ログイン不可に
# groupadd www
# useradd -g www www
# usermod -s /bin/false www

実行ユーザーの変更
# vim /etc/nginx/nginx.conf
 user  nginx;
 user www;

ルートディレクトリ作成・コピー
# mkdir /var/www/
# cp /usr/share/nginx/html/* /var/www/

ルートディレクトリ
# vim /etc/nginx/conf.d/default.conf
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    location / {
        root   /var/www;
        index  index.html index.htm;
    }

mysql、php関連インストール
# yum install --enablerepo=remi mysql mysql-server
# yum install --enablerepo=remi php php-fpm

# yum install --enablerepo=remi php-devel php-cli php-xml php-mysql php-mbstring php-gd phpmyadimn

php-fpm設定

#vim /etc/php-fpm.d/www.conf
 user = apache
 group = apache
 user = www
 group = www

phpが使えるようにnginxを設定
# vim /etc/nginx/conf.d/default.conf
    location / {
        root   /var/www;
        index  index.html index.htm index.php;

        if (!-e $request_filename) {
            rewrite ^/(.+)#  /index.php?q=$1 last;
            break;
        }
    }
〜〜〜〜〜〜〜〜〜〜〜〜
    location ~ \.php$ {
        root           /var/www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

テストページ作成
# echo '<?php echo phpinfo(); ?>' > /var/www/test.php

トップページのリネーム
# mv index.html index.php

php-fpmの起動・自動設定
# service php-fpm start
# chkconfig php-fpm on

テストページの確認
# service nginx restart
ブラウザでroot/test.phpにアクセス。phpのバージョン情報が出てくれば成功。

長くなったのでsqlは次回へ

0 件のコメント:

コメントを投稿