75
80

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

nginxとphp-fpmの設定

Last updated at Posted at 2015-03-04

準備

最新のphpなどをインストールするためにレポジトリの追加を行う

epel

http://dl.fedoraproject.org/pub/epel/6/
epel-release-xxx.noarch.rpm

例)sudo rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

remi

http://rpms.famillecollet.com/enterprise/6/remi/
remi-release-xxx.xxx.remi.noarch.rpm

例)sudo rpm -ivh http://rpms.famillecollet.com/enterprise/6/remi/i386/remi-release-6.5-1.el6.remi.noarch.rpm

レポジトリの追加
sudo rpm -ivh URL

PHPのインストール

sudo yum -y install --enablerepo=remi --enablerepo=remi-php55 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug

/etc/php.iniの編集

; デフォルトの文字コード
default_charset = "UTF-8"

; タイムゾーンの設定
date.timezone = "Asia/Tokyo"

[mbstring]
; デフォルト言語の設定
mbstring.language = Japanese

MySQLのインストール

sudo yum -y --enablerepo=remi install mysql-server

/etc/my.cofの編集

[mysqld]
character-set-server = utf8
skip-character-set-client-handshake

[mysql]
default-character-set = utf8

Mysqlの起動とサービス化

起動
sudo service mysqld start

サービス化
sudo chkconfig mysqld on

rootのパスワードを設定

mysqladmin -u root password パスワード

nginxのインストール

sudo yum -y install nginx

/etc/nginx/conf.d/xxx.confの編集

server {
  listen 80;
  server_name xxx.com;
  root /path/to/xxx;
  index index.php index.html;

  location / {
    if (!-e $request_filename) {
      rewrite ^/(.+)#  /index.php?q=$1 last;
      break;
    }
  }
  
  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME /path/to/xxx$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    include fastcgi_params;
  }
}

nginxの起動とサービス化

起動
sudo service nginx start

サービス化
sudo chkconfig nginx on

php-fpmのインストール

sudo yum -y --enablerepo=remi-php55,remi install php-fpm

/etc/php-fpm.d/www.confの編集

apacheになっているところをnginxに変更

user = nginx
group = nginx

php-fpmの起動をサービス化

起動
sudo service php-fpm start

サービス化
sudo chkconfig php-fpm on

phpmyadminのインストールと設定

インストール

sudo yum --enablerepo=remi,remi-php55 install -y phpMyAdmin php-mysql php-mcrypt

インストールされたディレクトリのリネーム

sudo mv /usr/share/phpMyAdmin /usr/share/phpmyadmin

/etc/nginx/conf.d/default.confに追記

    location /phpmyadmin {
        root /usr/share;
        index index.php;

        location ~ ^/phpmyadmin.+\.php$ {
             # fastcgi_pass unix:/var/run/php5-fpm.sock;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index index.php;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
             include fastcgi_params;
        }

    }

/etc/php.iniの編集

session.save_path = "/var/lib/php/session"
を追記

アクセス権を付与

sudo chmod 777 /var/lib/php/session
注意)フルアクセスなので危険です。

75
80
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
75
80

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?