12
14

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

AWS EC2にNginx1.8 + php7 + Laravel5をインストール

Last updated at Posted at 2016-05-20

PHP7のリポジトリを追加

$ sudo rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

PHP7インストール

$ sudo yum install --enablerepo=webtatic-testing php70w php70w-devel php70w-fpm  php70w-mysql php70w-mbstring php70w-pdo php70w-xml
# 自動起動設定
$ sudo chkconfig php-fpm on

nginxのインストール

$ sudo yum install nginx
# 自動起動設定
$ sudo chkconfig nginx on

nginx設定

/etc/nginx/nginx.conf

# 下記を修正
root         /var/www/html;
# 下記を追加
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
    include        fastcgi_params;
}

mysql(server, client)のインストール

# mysql5.6のリポジトリを追加
$ sudo rpm -ihv http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
$ sudo yum install mysql-server mysql
# 自動起動設定
$ sudo chkconfig mysqld on

ユーザー作成

$ sudo useradd app

www グループをインスタンスに追加

$ sudo groupadd www

ユーザーを www グループに追加

$ sudo usermod -a -G www app
# ログアウト
$ exit

# インスタンス再接続しgroupsを確認
$ sudo su - app
$ groups
app www

グループ所有者・アクセス権を変更

sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;

php-fpm設定

/etc/php-fpm.d/www.conf

user = app
group = www

nginx/php-fpm起動

sudo service nginx start
sudo service php-fpm start

PHPの動作確認

$ sudo su - app
$ echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

ブラウザで動作確認

http://[パブリックip]/phpinfo.php

Composerをインストール

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv /home/ec2-user/composer.phar /usr/local/bin/composer

laravelをインストール

$ sudo su - app
composer global require "laravel/installer"

project作成

$ sudo su - app
$ cd /var/www/html/
$ composer create-project --prefer-dist laravel/laravel test
$ cd test
$ composer install
$ php artisan key:generate

Laravel用にnginx設定を修正

/etc/nginx/nginx.conf

# 以下を修正
root         /var/www/html/test/public;

location / {
    # 以下を追加
    try_files $uri /index.php?$query_string;
}

location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    # 以下を修正
    fastcgi_param  SCRIPT_FILENAME  /var/www/html/test/public$fastcgi_script_name;
    include        fastcgi_params;
}

nginxとphp-fpm 再起動

sudo service nginx restart
sudo service php-fpm restart

ブラウザで動作確認

http://[パブリックip]
でLaravel5 TOP画面が表示されることを確認

参考

http://owani.net/php/php7-nginx/285/
http://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/install-LAMP.html

12
14
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
12
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?