Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?

More than 1 year has passed since last update.

@dora1341

AmazonLinux2 Nginx+PHP-fpm環境構築メモ

はじめに

表題の構成で作った際の手順メモ。

手順

初期設定

# パッケージ更新
$ sudo yum update -y

# タイムゾーン変更
$ timedatectl status
$ sudo timedatectl set-timezone Asia/Tokyo

# 日本語ロケール追加
$ localectl status
$ sudo localectl set-locale LANG=ja_JP.UTF-8
$ sudo localectl set-keymap jp106

nginxインストール

# 対象確認
$ amazon-linux-extras list
$ amazon-linux-extras info nginx1

# インストール
$ sudo amazon-linux-extras install nginx1

# インストール確認
$ nginx -v

phpインストール

# 対象確認
$ amazon-linux-extras list
$ amazon-linux-extras info php7.4

# インストール
$ sudo amazon-linux-extras install php7.4

# 動作確認
$ php --version
PHP 7.4.5 (cli) (built: Apr 23 2020 00:10:21) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

php.ini書き換え

# HTTPヘッダへのPHPバージョン記載をOFF
# expose_php = On
expose_php = Off

# 念のためメモリ上限をアップ
# memory_limit = 128M
memory_limit = 256M

# POST送信許容サイズアップ
# post_max_size = 8M
post_max_size = 16M

# アップロード許容サイズアップ
# upload_max_filesize = 2M
upload_max_filesize = 16M

# timezoneの設定
# date.timezone =
date.timezone = Asia/Tokyo

php-fpm自動起動設定

$ sudo systemctl start php-fpm.service
$ sudo systemctl enable php-fpm.service
$ systemctl status php-fpm.service

UNIXドメインソケット接続設定

nginxとphp-fpmのUNIXドメインソケット接続確認

$ netstat -al --protocol=unix | egrep "Proto|fpm"
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     1486761  /run/php-fpm/www.sock

www.confを編集

# www.conf編集
$ sudo vim /etc/php-fpm.d/www.conf

# 以下のような形で編集
- user = apache
+ user = nginx
- group = apache
+ group = nginx

#php-fpm再起動
$ sudo systemctl restart php-fpm.service

接続確認

# スーパーユーザーへ切替
$ sudo su

#接続確認用phpファイル追加
$ echo '<?php phpinfo(); ?>' > /usr/share/nginx/html/phpinfo.php

#ブラウザ確認
$ パブリックDNS/phpinfo.php

参考にさせていただいたページ

https://ninolog.com/set-amazonlinux2-aws-ec2/
https://qiita.com/2no553/items/968068b1752ea6154beb

2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
2
Help us understand the problem. What is going on with this article?