2017年1月12日木曜日

AWS Centos6.5 nginx php-fpm インストール

  • このエントリーをはてなブックマークに追加


AWS Centos6.5 nginx php-fpm インストールAWSのEC2(CentOS 6.5)にnginx、PHP-fpmのインストール手順をメモしておきます。

nginx install

sudo sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
sudo yum install nginx

php-fpm install

sudo yum install php
yum list | grep php-fpm

php-fpm 設定

sudo cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org
sudo sed -i -e 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf

sudo sed -i -e 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf

直接viで編集してもよい。ユーザー、groupをnginxに変更

nginx 設定

例:rootディレクトリを/var/www/htmlにする
sudo cp -p /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
以下の様な感じで変更
server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /var/www/html;
index index.php index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var
/www/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

起動

sudo /etc/init.d/php-fpm start
sudo /etc/init.d/nginx start

自動起動を設定
sudo chkconfig nginx on
sudo chkconfig php-fpm on

動作確認

sudo echo '' > /var/www/html/phpinfo.php
この状態だと、アクセス拒否されてできないです。
AWSインスタンスで既定でiptables,ip6tablesが有効になっているからです。
無効にする
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo chkconfig iptables off
sudo chkconfig ip6tables off
以上でnginxとphp連携できた。

この記事がお役にたちましたらシェアをお願いします:)

  • このエントリーをはてなブックマークに追加

0 件のコメント:

コメントを投稿