LoginSignup
33
34

More than 5 years have passed since last update.

YumでNginxセットアップ+PHP-FPM

Last updated at Posted at 2015-09-02

忘備録
【OS】
今回はCentOS7.1_x86_64版を使用。詳細は以下を参照。
http://www.server-world.info/query?os=CentOS_7&p=install
事前準備
セットアップに必要なパッケージを事前に設定しておく必要がある。以下を全て設定する。
システム変更が発生するので管理者権限が必須。rootにsuしておく事。

【YUMパッケージ管理】
yum -y install yum-plugin-priorities
yum -y update
yum -y groupinstall "Base" "Development tools" "Japanese Support"

[EPELリポジトリ追加]
yum -y install epel-release
[Remiリポジトリ追加]
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
[RPMforgeリポジトリ追加]
yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm

【SELinux無効化】
vi /etc/selinux/config


SELINUX=enforcing 
SELINUX=disabled ←変更(起動時に無効にする)

Nginx をEPELからインストールします。
yum --enablerepo=epel -y install nginx

Nginx の基本設定です。
vi /etc/nginx/nginx.conf


38行目:サーバー名変更
server_name www.sample.com;

Nginx起動
systemctl start nginx
systemctl enable nginx

任意のクライアントで Web ブラウザを起動し、デフォルトページにアクセスして動作確認してください。以下のようなページが表示されれば OK です。
image

PHP および PHP-FPM をインストールします。
yum --enablerepo=remi-php56 -y install php php-mbstring php-pear php-fpm

PHP-FPM と Nginx の設定です。
vi /etc/php-fpm.d/www.conf


23行目:変更
user = apache
   ↓
user = nginx

25行目:変更
group = apache
   ↓
group = nginx

PHP-FPM起動
systemctl start php-fpm
systemctl enable php-fpm

Nginxコンフィグレーション変更
vi /etc/nginx/nginx.conf


server セクション内に追記
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO $fastcgi_path_info;
            include        fastcgi_params;
        }

Nginx再起動
systemctl restart nginx

PHPInfo を作成して PHP の動作確認をしてください。以下のようなページが表示されれば OK です。


echo "<?php phpinfo() ?>" > /usr/share/nginx/html/info.php

image
33
34
0

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
33
34