PHP 製フレームワーク Laravel 6.x のインストール

環境

  • CentOS7
  • PHP7.3
  • Nginx
  • Laravel6.x

composer インストール

$ cd /path/to/your/project
$ mkdir bin
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ php composer-setup.php --install-dir=bin --filename=composer
# composer コマンドを使えるか確認
$ bin/composer -V
$ rm composer-setup.php

laravel インストール

$ cd /path/to/your/project
# プロジェクト名を入力していないと laravel というディレクトリができる
$ bin/composer create-project --prefer-dist laravel/laravel

パーミッション変更

$ cd /path/to/your/project
$ chmod -R 0777 laravel/storage
$ chmod -R 0777 laravel/bootstrap/cache

Nginx の設定

server {
    listen       80;
    server_name  laravel.sample.com;

    root /var/www/html/laravel-sample/laravel/public;

    index index.php index.html;

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

    # using PHP
    #
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index /index.php;

        include /etc/nginx/fastcgi_params;

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param PATH_INFO       $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    # using PHP Framework
    #
    try_files $uri $uri/ @rewrite;

    location @rewrite {
        rewrite ^(.*)$ /index.php?_url=$1;
    }
    location ~* ^/(css|img|js|flv|swf|download)/(.+)$ {
        root /var/www/html/laravel-sample/laravel/public;
    }

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