Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kenzo0107/d78d609bb213a1db08b4 to your computer and use it in GitHub Desktop.
Save kenzo0107/d78d609bb213a1db08b4 to your computer and use it in GitHub Desktop.

CentOS 7 + Nginx + MySQL5.6 + PHP5.6 (Laravel5.1) インストール nginx+php-fpmで動作確認まで

環境

  • AWS EC2 t2.micro
  • CentOS Linux release 7.0.1406 (Core)
  • PHP 5.6.11
  • MySQL 5.6
  • Laravel Framework version 5.1.7 (LTS)

Nginx インストール

https://gist.github.com/kenzo0107/7436d67051ee28f24965

PHP 5.6 インストール

http://kenzo0107.hatenablog.com/entry/2015/07/16/114113

MySQL 5.6

http://kenzo0107.hatenablog.com/entry/2015/07/16/154810


Laravel インストール

上記までで以下がインストールされている状態です。

  • Nginx 1.9.3
  • php 5.6
  • MySQL 5.6

composerインストール

Laravelはcomposerからインストールする為、必要になります。

# curl -sS https://getcomposer.org/installer | php
# mv composer.phar /usr/local/bin/composer

Laravelを /usr/share/nginx/ にインストール

※2015/07/16時点ではバージョン 5.1.7

以下, は適宜修正してください。

$ cd /usr/share/nginx
$ composer create-project laravel/laravel <project_name> dev-master --prefer-dist
$ sudo chmod -R <user>:<group> <project_name>
$ cd <project_name>
$ chmod -R 0777 storage/

php-fpm 設定

user / group を nginx に設定

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

# TCP/IP でなく Unix Socket通信で高速化
- listen = 127.0.0.1
+ listen = /var/run/php-fpm/php-fpm.sock

- user = apache
+ user = nginx

- group = apache
+ group = nginx

- listen.user = apache
+ listen.user = nginx

- listen.group = apache
+ listen.group = nginx
# systemctl restart php-fpm
# systemctl enable php-fpm

Nginx 設定

  • Nginx で php-fpmを利用する。
  • ドキュメントルートを <project_name>/public/ディレクトリに設定する。
nginx default.conf設定
# vi /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  ec2-xx-xx-xxx-xx.ap-northeast-1.compute.amazonaws.com;

    # Document Root設定
    root   /usr/share/nginx/<project_name>/public;
    # Indexファイル設定
    index  index.php index.html index.htm;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        
        fastcgi_max_temp_file_size 0;
        fastcgi_buffer_size 4K;
        fastcgi_buffers 64 4k;
        
        include        fastcgi_params;
    }
}

Laravel Topページにアクセス

以下の様に表示されればひとまず設定完了です。

Imgur

以上

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment