Laravel Toolkit
概要: Laravel Toolkit は無料の Plesk 拡張です。これを使用して、Laravel アプリケーションのホスティングに関連する定型タスクを簡素化できます。
このトピックでは、Plesk で Laravel アプリケーションをアップロード、設定、実行する方法について説明します。このトピックでは、既にアプリケーションを用意しているか、アプリケーションの作成を計画していることを前提としており、Laravel アプリケーションの作成方法を説明するものではありません。
前提条件
Laravel アプリケーションをホストする前に、無料の Laravel Toolkit 拡張を Plesk サーバにインストールする必要があります。
- Plesk 管理者の場合は、拡張カタログから拡張をインストールします。
- それ以外の場合は、ホスティング事業者に連絡して拡張をインストールしてもらえるか確認してください。
Once the extension is installed, you are ready to begin. You will see the Laravel button in the drawer on the left side of the screen, and also the Laravel button on the Install Application drawer on the domain cards of all your domains.
アプリケーションをアップロードする
アプリケーションを構成して実行する前に、Plesk サーバにアップロードして Laravel Toolkit に登録する必要があります。これには 3 つの方法があります。
- Laravel スケルトンを作成する。アプリケーションがコンピュータ上のフォルダまたは圧縮ファイルに格納されている場合、あるいはアプリケーションを最初から作成しようとしている場合は、Laravel Toolkit が必要なディレクトリ構造とローカル Git リポジトリを作成できます。
- リモート Git リポジトリからインストールする。アプリケーションがリモートリポジトリに格納されている場合は、Plesk サーバにこれを展開できます。
- 既存のアプリケーションをスキャンする。既にアプリケーションを Plesk にアップロードした場合は、このアプリケーションをスキャンすることで Laravel Toolkit にアプリケーションを登録できます。
注釈: Laravel スケルトンを作成するか、リモート Git リポジトリからインストールするためには、Plesk サーバに無料の Git 拡張 をインストールする必要があります。
Laravel スケルトンを作成する
- Plesk にログインします。
- Go to Websites & Domains, find the domain that will host your application, and then click Install Application > Laravel.
- [スケルトンをインストール]を選択して、[アプリケーションをインストール]をクリックします。
- スケルトンがインストールされたら、アプリケーションファイルを Plesk にアップロードする必要があります(たとえば、FTP または ファイルマネージャを使用)。デフォルトファイルは必要に応じて置き換えます。
リモート Git リポジトリからインストールする
- Plesk にログインします。
- Go to Websites & Domains, find the domain that will host your application, and then click Install Application > Laravel.
- [リポジトリからインストール]を選択します。
- アプリケーションのファイルが含まれるリモートリポジトリの URL を入力するか貼り付けます。
- このリモートリポジトリで認証が必要な場合は、このページに表示された公開鍵をリポジトリに追加します。
- [アプリケーションのインストール]をクリックします。
既存のアプリケーションをスキャンする
- Plesk にログインします。
- [ウェブサイトとドメイン]で、アプリケーションをホストするドメインを見つけて[ホスティングと DNS]タブを開きます。
- [ホスティング設定]をクリックします。
- 「ドキュメントルート」の値を、アプリケーションの公開ディレクトリのパスに変更し(デフォルトでは
/httpdocs/public
)、[OK]をクリックします。 - [Laravel アプリケーションをインストール] > [キャンセル] > [スキャン]の順にクリックします。
Once you have uploaded or deployed your application's files and your application has been registered in Laravel Toolkit, the Laravel button will appear on the card of the domain hosting your application.
次のステップに進めます。
Artisan、Composer、Node.js コマンドを実行する
Laravel アプリケーションを管理するには、Artisan、Composer、Node.js コマンドの実行が必要になる可能性があります。Laravel Toolkit により、Plesk インターフェースからこれらのコマンドを簡単に実行できるため、シェルアクセスは必要ありません。
アプリケーションを正常に機能させるために、Artisan、Composer、Node.js コマンドを実行する必要があるかどうかわからない場合は、このアプリケーションの提供元である人または組織にお問い合わせください。
注釈: Node.js コマンドを実行するためには、無料の Node.js 拡張を Plesk サーバにインストールする必要があります。
Artisan、Composer、または Node.js コマンドを実行する
-
Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
-
該当するタブに移動し、実行するコマンドを入力するかリストから選択して、Enter キーを押すか
ボタンをクリックします。
注釈: Node.js コマンドを実行する際は、コマンドで必要な効果を得られるように、特定の Node.js バージョンやパッケージマネージャを指定する必要がある場合があります。どれを選択すべきかわからない場合は、このアプリケーションの提供元である人または組織にお問い合わせください。
アプリケーションのログファイルを表示する
Laravel アプリケーションは、実行中にログを個別のログファイルに記録します。このファイルの内容は Laravel Toolkit インターフェースから確認できるため、アプリケーションのモニタリングや発生した問題のトラブルシューティングが簡単になります。
アプリケーションのログを表示する
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [ログ]をクリックします。
ドメインログブラウザが開き、Laravel ログのログエントリのみが表示されます。
アプリケーションのスケジュール済みタスクを表示する
Laravel では、cron などの外部スケジューラを使用する代わりに、アプリケーションのコード内でタスクをスケジュールできます。Laravel Toolkit により、現在設定されているスケジュール済みタスクを Laravel Toolkit インターフェースから直接表示したり、Laravel のスケジュール済みタスクを有効化または無効化したりできます。
注釈: Laravel Toolkit インターフェースから Laravel のスケジュール済みタスクを 追加、削除、編集することはできません。 アプリケーションのコード内でタスクをスケジュールする方法をご確認ください
アプリケーションのスケジュール済みタスクを表示する
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [スケジュール済みタスク]タブに移動します(このタブは、スケジュール済みタスクが 1 つ以上設定されている場合にのみ表示されます)。
注釈: アプリケーションのスケジュール済みタスクを有効化または無効化するためには、まず特定の処理を実行する必要があります。この処理は、Plesk for Linux と Plesk for Windows のどちらを使用しているかによって異なります。スケジュール済みタスクを実行したい Laravel アプリケーションをホストしているドメインごとに、この処理を行う必要があります。
Enabling scheduled tasks management
- Plesk にログインします。
- Enable the "Scheduler management" permission (found on the "Permissions" tab) for the subscription to which the domain hosting your application belongs.
- (Plesk for Linux) Go to Websites & Domains, find the domain hosting your application, go to the "Hosting & DNS" tab, and then click Web Hosting Access.
- (Plesk for Linux) Under "Access to the server over SSH", select any option other than "Forbidden", and then click OK.
これで、アプリケーションのスケジュール済みタスクを有効または無効にできます。
アプリケーションのスケジュール済みタスクを有効にする
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [スケジュール済みタスク]トグルボタンをクリックして、[有効]と表示させます。
これで、Laravel アプリケーションのスケジュール済みタスクが有効になります。
環境変数を編集する
アプリケーションが適切に機能するためには、カスタム環境変数が 1 つ以上必要である可能性があります。あるいは、設定されている環境変数に応じて、アプリケーションの挙動が変わる可能性があります。アプリケーションを適切に機能させるために必要な環境変数があるかどうかわからない場合は、このアプリケーションの提供元である人または組織にお問い合わせください。
環境変数を編集する
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [環境変数(.env)]の横の[編集]ボタンをクリックします。
- 必要に応じて環境変数を編集して、[更新]をクリックします。
更新された環境変数が有効になります。
アプリケーションをメンテナンスモードにする
アプリケーションでの作業中や更新作業中にウェブサイトの訪問者に各種エラーが表示されないようにするために、アプリケーションをメンテナンスモードに設定できます。アプリケーションをメンテナンスモードにすると、ウェブサイトの訪問者には「503 SERVICE UNAVAILABLE」エラーのページが表示されます。
アプリケーションをメンテナンスモードにする
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [メンテナンスモード]トグルボタンをクリックして、[有効]が表示されるようにします。
Laravel アプリケーションはメンテナンスモードになります。
注釈: アプリケーションでの作業や更新が終了したら、忘れずにメンテナンスモードを終了させてください。
アプリケーションを更新する
Laravel アプリケーションのファイルが保存されている Git リポジトリがローカルとリモートのどちらであっても、アプリケーションのコードに加えた変更が Plesk サーバに伝達されていることを確認する必要があります。変更を手動で適用するか自動的に適用するかを選択できます。
アプリケーションを更新するタイミングを厳密に管理する必要がある場合、手動での更新をお勧めします。これにより、リポジトリでアプリケーションのコードにいかなる変更を加えても、準備が整うまでは Plesk サーバに変更が反映されなくなります。このアプローチの欠点は、アプリケーションを更新する必要があるたびに管理者が手作業で実施する必要があることです。
アプリケーションを手動で更新する
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [デプロイメント]タブに移動して、[デプロイメントモード]の下で[手動]ラジオボタンをオンにします。
- [デプロイメントシナリオ]の下で、デプロイメント作業中に実行したくない手順のチェックボックスをオフにしてから、[デプロイ]をクリックします。
Laravel Toolkit ですべてのデプロイメント手順を実行すると、アプリケーションと依存関係が更新されます。
アプリケーションのコードに加えた変更を Plesk サーバに自動で反映させたい場合、その方法は、アプリケーションのコードを保存している Git リポジトリがローカルかリモートかに応じて異なります。
アプリケーションを自動的に更新する(ローカルリポジトリ)
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [デプロイメント]タブに移動して、[デプロイメントモード]の下で[自動]ラジオボタンをオンにします。
- [デプロイメントシナリオ]の下で、デプロイメント作業中に実行したくない手順のチェックボックスをオフにします。
これで、アプリケーションのコードが保存されているローカルリポジトリの master
ブランチにコミットがプッシュされるたびに、アプリケーションと依存関係が更新されるようになります。
アプリケーションを自動的に更新する(リモートリポジトリ)
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- ここで表示されるウェブフック URL をコピーして、リモートリポジトリに追加します。具体的な手順については、リポジトリプロバイダのマニュアルを参照してください。
- [デプロイメント]タブに移動して、[デプロイメントモード]の下で[自動]ラジオボタンをオンにします。
- [デプロイメントシナリオ]の下で、デプロイメント作業中に実行したくない手順のチェックボックスをオフにします。
これで、アプリケーションのコードが保存されているリモートリポジトリでウェブフックを起動するイベントが発生するたびに、アプリケーションと依存関係が更新されるようになります。
デプロイメントスクリプトを構成する
アプリケーションを正常に機能させるためには、デプロイメント中にサーバで特定のコマンドを実行する必要がある可能性があります。コマンドを手動で実行することを避けるには、アプリケーションが更新されるたびに実行されるデプロイメントスクリプトを設定できます。
アプリケーションを正常に機能させるために、デプロイメント中に何らかのコマンドを実行する必要があるかどうかわからない場合は、このアプリケーションの提供元である人または組織にお問い合わせください。
注釈: Plesk for Linux では、Laravel Toolkit インターフェースからデプロイメントスクリプトを編集する前に、SSH アクセスを有効にする必要があります。これは一度だけ行う作業です。
Plesk for Linux でデプロイメントスクリプトの編集機能を有効にする
- Plesk にログインします。
- [ウェブサイトとドメイン]に移動し、アプリケーションをホストするドメインを探し、[ホスティングと DNS]タブに移動して[ウェブホスティングアクセス]をクリックします。
- [SSH 経由のサーバアクセス]の下で、[禁止]以外のいずれかのオプションを選択して、[OK]をクリックします。
これで、Laravel Toolkit インターフェースでデプロイメントスクリプトを編集できるようになります。
デプロイメントスクリプトを編集する
- Plesk にログインします。
- Go to Websites & Domains, find the domain hosting your application, and then click Laravel.
- [デプロイメント]タブに移動して、[スクリプトを編集]をクリックします。
- デプロイメントスクリプトを入力するか貼り付けてから、[更新]をクリックします。
デプロイメントスクリプトが有効になり、アプリケーションを更新するたびに実行されるようになります。
Managing Queues
Queues in Laravel make it possible to process time-consuming tasks, such as parsing an uploaded file, asynchronously in the background. If your application supports queues, you can enable them in Plesk to configure the queue worker process.
To use queues, you need to enable them for your subscription, and also to create a database for the queue worker to use. This is a one time procedure.
Laravel queues can use a variety of queue backends. However, in this guide we will only cover using a MySQL database as backend. This is the simplest way to enable queues in Plesk, and it should be sufficient for most users. Other backends may provide advantages, such as improved access times, but they require expertise to implement and maintain, and may also incur additional costs.
Enabling queues
-
Log in to Plesk, and then locate the domain hosting your application.
-
Enable scheduled tasks for your application. This is necessary for queues to function.
-
In your application's Git project repository, add the following line to the "require" section of the
composer.json
file:"plesk/ext-laravel-integration": "^7.0"
注釈: In each section of the
composer.json
file, every line except the last one must end with a comma.If you use a local Git repository, do not make this change via File Manager. Instead, commit changes to the repository. This is to avoid the changes being overwritten the next time you deploy your application.
-
Click Laravel, go to the "Deployment" tab, and then click Deploy. This will result in changes being made to the contents of the
composer.lock
file. Commit those changes to the repository to avoid the changes being overwritten the next time you deploy your application. -
After committing the changes, click Deploy once again.
-
(Optional) Return to the domain card, go to Databases, and then click Add Database.
注釈: If your Laravel application is already using a MySQL database, you can use that database to enable queues. In that case, skip this step, and also the following step.
-
(Optional) Create a MySQL or MariaDB database, and a database user.
-
Return to the domain card, click Laravel, and then click the Edit button next to "Environment variables (.env)".
-
Add the following lines to the
.env
file, replacing the placeholders with the information about the database you want to use (either the one just created, or the one already being used by your Laravel application):DB_CONNECTION=mysql DB_HOST=<database server IP address or hostname> QUEUE_CONNECTION=database DB_DATABASE=<database name> DB_USERNAME=<database user name> DB_PASSWORD=<database user password>
and then click "Update".
-
Go to the "Artisan" tab, and then run the following commands, in this order:
queue:table
migrate
-
Go to the "Dashboard" tab, take your Laravel application out of maintenance mode, and then click the Queue toggle button so that it shows "Enabled".
Queues are now enabled for your Laravel application.
To make the queue worker process use server resources more efficiently, there is a number of settings you can configure in Plesk. They mostly deal with conditions under which the queue worker process may exit, freeing the memory it has been using.
Configuring the queue worker process
-
Log in to Plesk, and then locate the domain hosting your application.
-
Click Laravel, and then go to the "Queue" tab.
-
(Optional) Select the "Stop Worker When Empty" checkbox to configure the worker process to stop when there are no jobs in the queue. If you do, the worker process will start every 60 seconds, process all jobs currently in the queue, and then exit.
If you do not select the "Stop Worker When Empty" checkbox, the worker process will remain running even when there are no jobs in the queue.
-
(Optional) Set a custom "Timeout" value to configure the worker process to exit with an error if job has been running for a length of time exceeding the configured value. Make sure that the "Timeout" value allows enough time for a typical job created by your Laravel application to finish.
If you do not set a custom "Timeout" value, the worker process will not exit even if an individual job has been in the queue being processed for a long time (for example, because the job has become stuck).
ご用心: Setting too low a value may result in jobs failing because of insufficient time to process (for example, when uploading a large file). If you start experiencing failed jobs after setting a custom "Timeout" value, consider increasing it or returning the parameter to its default value ("0", indicating no limit on job processing time).
-
(Optional) Set a custom "Max Jobs" value to configure the worker process to exit once it has processed a certain number of jobs.
If you do not set a custom "Max Jobs" value, the worker process will not stop, even if it has processed a large number of jobs.
-
(Optional) Set a custom "Max Time" value to configure the worker process to exit once it has been running for the specified number of seconds (the worker process will not exit while in the middle of processing a job).
If you do not set a custom "Max Time" value, the worker process will keep running even if it has been running for a long time.
The queue worker process has been configured and should now use server resources more efficiently.
Jobs may fail due to any number of circumstances. Plesk keeps track of failed jobs, which you can restart or dismiss.
Viewing, restarting, and dismissing failed jobs
- Log in to Plesk, and then locate the domain hosting your application.
- Click Laravel, go to the "Queue" tab, and then click Show failed jobs to see the list of failed jobs.
- (Optional) Select one or more failed jobs, and then click Retry to restart them.
- (Optional) Select one or more failed jobs, and then click Delete to remove them from the list.
- (Optional) Click Flush to remove all failed jobs from the list.
Failed jobs have now been restarted and/or dismissed.