インストールInstallation
サーバ要件Server Requirements
Laravelフレームワークを動作させるには多少のシステム要件があります。Laravel Homestead仮想マシンでは、要求がすべて満たされています。そのため、Laravelのローカル開発環境としてHomesteadを活用されることを強く推奨します。The Laravel framework has a few system requirements. All of these requirements are satisfied by the Laravel Homestead[/docs/{{version}}/homestead] virtual machine, so it's highly recommended that you use Homestead as your local Laravel development environment.
しかし、Homesteadを使用しない場合は、以下の要件を満たす必要があります。However, if you are not using Homestead, you will need to make sure your server meets the following requirements:
LaravelのインストールInstalling Laravel
LaravelはComposerを依存パッケージの管理に使用しています。ですから、Laravelを始める前に、自分の開発機にComposerを確実にインストールしておいてください。Laravel utilizes Composer[https://getcomposer.org] to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine.
LaravelインストーラVia Laravel Installer
最初にComposerを使用し、Laravelインストーラをダウンロードします。First, download the Laravel installer using Composer:
composer global require laravel/installer
皆さんのシステムの、どこへlaravel実行ファイルが設置されても動作するように、Composerのシステム全体のvendor/binディレクトリを$PATHへ登録してください。このディレクトリはオペレーティングシステムにより場所が異なります。通常は、以下の場所です。Make sure to place Composer's system-wide vendor bin directory in your $PATH so the laravel executable can be located by your system. This directory exists in different locations based on your operating system; however, some common locations include:
グローバルなComposerのインストールパスを見つけるには、composer global aboutを実行し、最初の行を確認してください。You could also find Composer's global installation path by running composer global about and looking up from the first line.
インストールし終えたら、laravel newコマンドにより、指定したディレクトリに真新しいLaravelプロジェクトを作成できます。たとえば、laravel new blogを実行すると、blogという名前のディレクトリへ、必要とするパッケージが全部揃った、真新しいLaravelがインストールされます。Once installed, the laravel new command will create a fresh Laravel installation in the directory you specify. For instance, laravel new blog will create a directory named blog containing a fresh Laravel installation with all of Laravel's dependencies already installed:
laravel new blog
Composer Create-ProjectVia Composer Create-Project
ターミナルでComposerのcreate-projectコマンドを実行し、Laravelをインストールする方法もあります。Alternatively, you may also install Laravel by issuing the Composer create-project command in your terminal:
composer create-project --prefer-dist laravel/laravel blog "6.*"
ローカル開発サーバLocal Development Server
PHPがローカルにインストール済みで、PHPの組込み開発サーバをアプリケーションサーバとして使いたい場合は、serve Artisanコマンドを使用します。このコマンドは、開発サーバをhttp://localhost:8000として起動します。If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve Artisan command. This command will start a development server at http://localhost:8000:
php artisan serve
より堅牢なローカル開発の選択肢として、HomesteadとValetも利用できます。More robust local development options are available via Homestead[/docs/{{version}}/homestead] and Valet[/docs/{{version}}/valet].
設定Configuration
PublicディレクトリPublic Directory
Laravelをインストールできたら、Webサーバのドキュメント/Webルートがpublicディレクトリになるように設定してください。このディレクトリのindex.phpは、アプリケーションへ送信された、全HTTPリクエストを始めに処理するフロントコントローラとして動作します。After installing Laravel, you should configure your web server's document / web root to be the public directory. The index.php in this directory serves as the front controller for all HTTP requests entering your application.
設定ファイルConfiguration Files
フレームワークで使用する設定ファイルは、すべてconfigディレクトリ下に設置しています。それぞれのオプションにコメントがついていますので、使用可能なオプションを理解するため、ファイル全体に目を通しておくのが良いでしょう。All of the configuration files for the Laravel framework are stored in the config directory. Each option is documented, so feel free to look through the files and get familiar with the options available to you.
ディレクトリパーミッションDirectory Permissions
Laravelをインストールした後に、多少のパーミッションの設定が必要です。storage下とbootstrap/cacheディレクトリをWebサーバから書き込み可能にしてください。設定しないとLaravelは正しく実行されません。Homestead仮想マシンを使用する場合は、あらかじめ設定されています。After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead[/docs/{{version}}/homestead] virtual machine, these permissions should already be set.
アプリケーションキーApplication Key
次にインストール後に行うべきなのは、アプリケーションキーにランダムな文字列を設定することです。ComposerかLaravelインストーラを使ってインストールしていれば、php artisan key:generateコマンドが、あらかじめ設定しています。The next thing you should do after installing Laravel is set your application key to a random string. If you installed Laravel via Composer or the Laravel installer, this key has already been set for you by the php artisan key:generate command.
通常、この文字列は32文字にすべきです。キーは.env環境ファイルに設定されます。もし、.env.exampleファイルをまだ.envへコピーしていなければ、今すぐ行ってください。アプリケーションキーが設定されていなければ、ユーザーセッションや他の暗号化済みデーターは安全でありません!Typically, this string should be 32 characters long. The key can be set in the .env environment file. If you have not copied the .env.example file to a new file named .env, you should do that now. If the application key is not set, your user sessions and other encrypted data will not be secure!
その他の設定Additional Configuration
Laravelのその他の設定は、最初に指定する必要がありません。すぐに開発を開始しても大丈夫です! しかし、config/app.phpファイルと、その中の記述を確認しておいたほうが良いでしょう。アプリケーションに合わせ変更したい、timezoneやlocalのような多くのオプションが含まれています。Laravel needs almost no other configuration out of the box. You are free to get started developing! However, you may wish to review the config/app.php file and its documentation. It contains several options such as timezone and locale that you may wish to change according to your application.
以下のようなLaravelのコンポーネントについても、設定しておいたほうが良いでしょう。You may also want to configure a few additional components of Laravel, such as:
Webサーバ設定Web Server Configuration
ディレクトリ設定Directory Configuration
Laravelは常にWebサーバで設定した「Webディレクトリ」のルートから提供する必要があります。「Webディレクトリ」のサブディレクトリでLaravelアプリケーションを提供しようと試みてはいけません。そうした試みはアプリケーションの中に存在するセンシティブなファイルを曝してしまう可能性があります。Laravel should always be served out of the root of the "web directory" configured for your web server. You should not attempt to serve a Laravel application out of a subdirectory of the "web directory". Attempting to do so could expose sensitive files present within your application.
きれいなURLPretty URLs
ApacheApache
URLパスにフロントコントローラのindex.phpを付けなくても良いように、Laravelはpublic/.htaccessファイルを用意しています。LaravelをApache上で動作させるときは、確実にmod_rewriteモジュールを有効に設定し、そのサーバで.htaccessファイルを動作させます。Laravel includes a public/.htaccess file that is used to provide URLs without the index.php front controller in the path. Before serving Laravel with Apache, be sure to enable the mod_rewrite module so the .htaccess file will be honored by the server.
Laravelに用意されている.htaccessファイルが、インストールしたApacheで動作しない場合は、以下の代替設定を試してください。If the .htaccess file that ships with Laravel does not work with your Apache installation, try this alternative:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
NginxNginx
Nginxを使用する場合は、すべてのリクエストがindex.phpフロントコントローラへ集まるように、サイト設定に以下のディレクティブを使用します。If you are using Nginx, the following directive in your site configuration will direct all requests to the index.php front controller:
location / {
    try_files $uri $uri/ /index.php?$query_string;
}
HomesteadかValetを使用する場合は、きれいなURLの設定は自動的に行われます。When using Homestead[/docs/{{version}}/homestead] or Valet[/docs/{{version}}/valet], pretty URLs will be automatically configured.