Readouble

Laravel 8.x デプロイ

イントロダクションIntroduction

Laravelアプリケーションをプロダクションとしてデプロイする準備ができたら、アプリケーションをできるだけ確実かつ、効率的な実行を行うには、いくつか重要な手順を行う必要があります。このドキュメントでは、アプリケーションを確実にデプロイするため、重要なポイントを説明します。When you're ready to deploy your Laravel application to production, there are some important things you can do to make sure your application is running as efficiently as possible. In this document, we'll cover some great starting points for making sure your Laravel application is deployed properly.

サーバ要件Server Requirements

Laravelフレームワークにはいくつかのシステム要件があります。Webサーバへ確実に以下のPHP最低バージョンと拡張機能を用意してください。The Laravel framework has a few system requirements. You should ensure that your web server has the following minimum PHP version and extensions:

  • PHP7.3以上PHP >= 7.3
  • BCMath PHP 拡張BCMath PHP Extension
  • Ctype PHP 拡張Ctype PHP Extension
  • Fileinfo PHP 拡張Fileinfo PHP Extension
  • JSON PHP 拡張JSON PHP Extension
  • Mbstring PHP 拡張Mbstring PHP Extension
  • OpenSSL PHP 拡張OpenSSL PHP Extension
  • PDO PHP 拡張PDO PHP Extension
  • Tokenizer PHP 拡張Tokenizer PHP Extension
  • XML PHP 拡張XML PHP Extension

サーバ設定Server Configuration

NginxNginx

Nginxを実行しているサーバにアプリケーションをデプロイする場合は、以下の設定ファイルをWebサーバを設定するためのサンプルとして使用できます。大抵の場合、このファイルはサーバの設定に応じてカスタマイズする必要があります。サーバの管理についてサポートが必要な場合は、Laravel ForgeなどのファーストパーティのLaravelサーバ管理とデプロイサービスの使用を検討してください。If you are deploying your application to a server that is running Nginx, you may use the following configuration file as a starting point for configuring your web server. Most likely, this file will need to be customized depending on your server's configuration. If you would like assistance in managing your server, consider using a first-party Laravel server management and deployment service such as Laravel Forge[https://forge.laravel.com].

以下の設定のように、Webサーバがすべてのリクエストをアプリケーションのpublic/index.phpファイルへ確実に送信してください。プロジェクトルートからアプリケーションを提供すると、多くの機密性の高い設定ファイルがパブリックインターネットに公開されるため、index.phpファイルをプロジェクトのルートに移動しようとしないでください。Please ensure, like the configuration below, your web server directs all requests to your application's public/index.php file. You should never attempt to move the index.php file to your project's root, as serving the application from the project root will expose many sensitive configuration files to the public Internet:

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /srv/example.com/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

最適化Optimization

オートローダー最適化Autoloader Optimization

プロダクションへデプロイする場合、Composerのクラスオートローダマップを最適し、Composerが素早く指定されたクラスのファイルを確実に見つけ、ロードできるようにします。When deploying to production, make sure that you are optimizing Composer's class autoloader map so Composer can quickly find the proper file to load for a given class:

composer install --optimize-autoloader --no-dev

lightbulb">Tip!! オートローダを最適化することに加え、プロジェクトのソースコントロールリポジトリへ、composer.lockファイルをいつも確実に含めましょう。composer.lockファイルが存在すると、プロジェクトの依存パッケージのインストールが、より早くなります。{tip} In addition to optimizing the autoloader, you should always be sure to include a composer.lock file in your project's source control repository. Your project's dependencies can be installed much faster when a composer.lock file is present.

設定ローディングの最適化Optimizing Configuration Loading

アプリケーションをプロダクションへデプロイする場合、デプロイプロセスの中で、確実にconfig:cache Artisanコマンドを実行してください。When deploying your application to production, you should make sure that you run the config:cache Artisan command during your deployment process:

php artisan config:cache

このコマンドは、Laravelの全設定ファイルをキャッシュされる一つのファイルへまとめるため、設定値をロードする場合に、フレームワークがファイルシステムを数多くアクセスする手間を大いに減らします。This command will combine all of Laravel's configuration files into a single, cached file, which greatly reduces the number of trips the framework must make to the filesystem when loading your configuration values.

Note: note 開発時にconfig:cacheコマンドを実行する場合は、設定ファイルの中だけで、env関数を呼び出していることを確認してください。設定ファイルがキャッシュされてしまうと、.envファイルはロードされなくなり、.env変数に対するenv関数の呼び出し結果はすべてnullになります。{note} If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded and all calls to the env function for .env variables will return null.

ルートロードの最適化Optimizing Route Loading

多くのルートを持つ大きなアプリケーションを構築した場合、デプロイプロセス中に、route:cache Artisanコマンドを確実に実行すべきでしょう。If you are building a large application with many routes, you should make sure that you are running the route:cache Artisan command during your deployment process:

php artisan route:cache

このコマンドはキャッシュファイルの中の、一つのメソッド呼び出しへ全ルート登録をまとめるため、数百のルートを登録する場合、ルート登録のパフォーマンスを向上します。This command reduces all of your route registrations into a single method call within a cached file, improving the performance of route registration when registering hundreds of routes.

ビューロードの最適化Optimizing View Loading

実機環境へアプリケーションをデプロイする場合は、その手順の中でview:cache Artisanコマンドを実行すべきでしょう。When deploying your application to production, you should make sure that you run the view:cache Artisan command during your deployment process:

php artisan view:cache

このコマンドは全Bladeビューを事前にコンパイルし、要求ごとにコンパイルしなくて済むため、ビューを返すリクエストすべてでパフォーマンスが向上します。This command precompiles all your Blade views so they are not compiled on demand, improving the performance of each request that returns a view.

デバッグモードDebug Mode

config/app.php設定ファイルのデバッグオプションは、エラーに関する情報が実際にユーザーに表示される程度を決定します。デフォルトでは、このオプションは、.envファイルに保存されているAPP_DEBUG環境変数の値を尊重するように設定しています。The debug option in your config/app.php configuration file determines how much information about an error is actually displayed to the user. By default, this option is set to respect the value of the APP_DEBUG environment variable, which is stored in your .env file.

実稼働環境下では、この値は常にfalseである必要があります。本番環境でAPP_DEBUG変数がtrueに設定されていると、機密性の高い設定値がアプリケーションのエンドユーザーに公開されるリスクがあります。In your production environment, this value should always be false. If the APP_DEBUG variable is set to true in production, you risk exposing sensitive configuration values to your application's end users.

Forge/VaporによるデプロイDeploying With Forge / Vapor

Laravel ForgeLaravel Forge

自分のサーバ設定管理に準備不足であったり、堅牢なLaravelアプリケーション実行に必要な数多くのサービスすべての設定について慣れていなければ、Laravel Forgeは素晴らしい代替案です。If you aren't quite ready to manage your own server configuration or aren't comfortable configuring all of the various services needed to run a robust Laravel application, Laravel Forge[https://forge.laravel.com] is a wonderful alternative.

Laravel ForgeはDigitalOcean、Linode、AWSなど数多くのインフラプロバイダ上に、サーバを作成できます。それに加え、ForgeはNginx、MySQL、Redis、Memcached、Beanstalkなどのような、堅牢なLaravelアプリケーションを構築するために必要なツールを全部インストールし、管理します。Laravel Forge can create servers on various infrastructure providers such as DigitalOcean, Linode, AWS, and more. In addition, Forge installs and manages all of the tools needed to build robust Laravel applications, such as Nginx, MySQL, Redis, Memcached, Beanstalk, and more.

Laravel VaporLaravel Vapor

Laravel向け完全サーバレスのオートスケーリング開発プラットフォームが必要な場合は、Laravel Vaporをチェックしてください。Laravel Vaporは、AWSで動作するLaravelのサーバレス開発プラットフォームです。Vapor上でLaravelインフラを起動し、サーバレスのスケーラブルなシンプルさに魅了されてください。Laravel Vaporは、Laravelの作成者によりフレームワークとシームレスに連携するように調整されているため、普段通りにLaravelアプリケーションを書き続けられます。If you would like a totally serverless, auto-scaling deployment platform tuned for Laravel, check out Laravel Vapor[https://vapor.laravel.com]. Laravel Vapor is a serverless deployment platform for Laravel, powered by AWS. Launch your Laravel infrastructure on Vapor and fall in love with the scalable simplicity of serverless. Laravel Vapor is fine-tuned by Laravel's creators to work seamlessly with the framework so you can keep writing your Laravel applications exactly like you're used to.

章選択

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作