LoginSignup
22
23

More than 5 years have passed since last update.

nginxとphp-fpm

nginxの設定

  • nginxのインストール
$ sudo yum install -y nginx
  • サービスのスタート
$ sudo service nginx start
  • ドキュメントルートの確認

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

デフォルトではドキュメントルートが/usr/share/nginx/htmlになっている

ドキュメントルートは変更可能
変更後にphpを動かしたいために.phpファイルをドキュメントルートに設定する

php-fpmの設定

  • php-pfmのインストール
$ sudo yum install -y php-fpm
  • php用に設定変更

デフォルトではuser/groupはapacheになっている

$ sudo vim /etc/php-fpm/www.conf

user = nginx
group = nginx

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

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;
}
  • nginxとphp-fpmの再起動
$ sudo service nginx restart
$ sudo service php-fpm restart
  • サービスに登録
$ sudo chkconfig nginx on
$ sudo chkconfig php-fpm on

403エラーになるとき

  1. ルートディレクトリのパーミッションが755であるか
  2. ルートディレクトリ直下のindex.htmlのパーミッションが755
  3. locationのallow denyが適切か
  4. ルートディレクトリのユーザとグループが指定のものか

※今回の場合、userがnginx、groupがnginxで設定する

$ sudo chmod -R 755 hoge
$ sudo chown -R nginx:nginx hoge

それでもエラーが出る場合はエラーログ

$ tail -f /var/log/nginx/error.log
22
23
1

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
22
23