6
4

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 3 years have passed since last update.

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

Last updated at Posted at 2020-06-12

はじめに

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

手順

初期設定

# パッケージ更新
$ 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

6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?