Readouble

Laravel 10.x Laravel Valet

イントロダクションIntroduction

lightbulb Note: macOS上でLaravelアプリケーションをより簡単に開発する方法をお探しですか?Laravel Herdをチェックしてください。Valet、PHP、Composerなど、Laravel開発を始めるために必要なものをHerdはすべて用意します。[!NOTE]
Looking for an even easier way to develop Laravel applications on macOS? Check out Laravel Herd[https://herd.laravel.com]. Herd includes everything you need to get started with Laravel development, including Valet, PHP, and Composer.

Laravel Valet(バレット:従者)は、macOSミニマリスト向けのLaravel開発環境です。Larave lValetは、マシンの起動時に常にバックグラウンドでNginxを実行するようにMacを設定します。次に、DnsMasqを使用して、Valetは*.testドメイン上のすべてのリクエストをプロキシし、ローカルマシンにインストールしているサイトへ転送します。Laravel Valet[https://github.com/laravel/valet] is a development environment for macOS minimalists. Laravel Valet configures your Mac to always run Nginx[https://www.nginx.com/] in the background when your machine starts. Then, using DnsMasq[https://en.wikipedia.org/wiki/Dnsmasq], Valet proxies all requests on the *.test domain to point to sites installed on your local machine.

言い換えれば、Valetは、約7MBのRAMを使用する非常に高速なLaravel開発環境です。Valetは、SailHomesteadの完全な代替ではありませんが、極端に速度を好むとかRAMの量が限られているマシンで作業しているなど、柔軟な開発環境の基本が必要な場合は優れた代替手段になるでしょう。In other words, Valet is a blazing fast Laravel development environment that uses roughly 7 MB of RAM. Valet isn't a complete replacement for Sail[/docs/{{version}}/sail] or Homestead[/docs/{{version}}/homestead], but provides a great alternative if you want flexible basics, prefer extreme speed, or are working on a machine with a limited amount of RAM.

Valetは以下をサポートしていますが、これらに限定されません。Out of the box, Valet support includes, but is not limited to:

  • LaravelLaravel[https://laravel.com]
  • BedrockBedrock[https://roots.io/bedrock/]
  • CakePHP 3CakePHP 3[https://cakephp.org]
  • ConcreteCMSConcreteCMS[https://www.concretecms.com/]
  • ContaoContao[https://contao.org/en/]
  • CraftCraft[https://craftcms.com]
  • DrupalDrupal[https://www.drupal.org/]
  • ExpressionEngineExpressionEngine[https://www.expressionengine.com/]
  • JigsawJigsaw[https://jigsaw.tighten.co]
  • JoomlaJoomla[https://www.joomla.org/]
  • KatanaKatana[https://github.com/themsaid/katana]
  • KirbyKirby[https://getkirby.com/]
  • MagentoMagento[https://magento.com/]
  • OctoberCMSOctoberCMS[https://octobercms.com/]
  • SculpinSculpin[https://sculpin.io/]
  • SlimSlim[https://www.slimframework.com]
  • StatamicStatamic[https://statamic.com]
  • Static HTMLStatic HTML
  • SymfonySymfony[https://symfony.com]
  • WordPressWordPress[https://wordpress.org]
  • ZendZend[https://framework.zend.com]

独自のカスタムドライバでValetを拡張できます。However, you may extend Valet with your own custom drivers[#custom-valet-drivers].

インストールInstallation

warning Warning! ValetにはmacOSとHomebrewが必要です。インストールする前に、ApacheやNginxなどの他のプログラムがローカルマシンのポート80をバインドしていないことを確認する必要があります。[!WARNING]
Valet requires macOS and Homebrew[https://brew.sh/]. Before installation, you should make sure that no other programs such as Apache or Nginx are binding to your local machine's port 80.

開始するには、最初にupdateコマンドを使用してHomebrewが最新であることを確認する必要があります。To get started, you first need to ensure that Homebrew is up to date using the update command:

brew update

次に、Homebrewを使用してPHPをインストールする必要があります。Next, you should use Homebrew to install PHP:

brew install php

PHPをインストールしたら、Composerパッケージマネージャをインストールする準備が整います。さらに、$HOME/.composer/vendor/binディレクトリがシステムの「PATH」にあることを確認する必要があります。Composerをインストールできたら、Laravel ValetをグローバルComposerパッケージとしてインストールできます。After installing PHP, you are ready to install the Composer package manager[https://getcomposer.org]. In addition, you should make sure the $HOME/.composer/vendor/bin directory is in your system's "PATH". After Composer has been installed, you may install Laravel Valet as a global Composer package:

composer global require laravel/valet

最後に、Valetのinstallコマンドを実行します。これにより、ValetとDnsMasqが設定およびインストールされます。さらに、Valetが依存しているデーモンが、システムの起動時に起動するように設定されます。Finally, you may execute Valet's install command. This will configure and install Valet and DnsMasq. In addition, the daemons Valet depends on will be configured to launch when your system starts:

valet install

Valetをインストールしたら、pingfoobar.testなどのコマンドを使用してターミナルの*.testドメインにpingを実行してみてください。Valetが正しくインストールされている場合、このドメインが127.0.0.1でレスポンスしているのがわかります。Once Valet is installed, try pinging any *.test domain on your terminal using a command such as ping foobar.test. If Valet is installed correctly you should see this domain responding on 127.0.0.1.

マシンが起動するたび、Valetは自動的に必要なサービスを開始します。Valet will automatically start its required services each time your machine boots.

PHPバージョンPHP Versions

lightbulb Note: グローバルにPHPバージョンを変更する代わりに、isolate コマンドを使い、サイトごとのPHPバージョンを使用するようにValetへ指示できます。[!NOTE]
Instead of modifying your global PHP version, you can instruct Valet to use per-site PHP versions via the isolate command[#per-site-php-versions].

Valetでは、valet use php@versionコマンドを使用してPHPのバージョンを切り替えることができます。Valetは、指定するPHPバージョンがまだインストールされていない場合、Homebrewを介してインストールします。Valet allows you to switch PHP versions using the valet use php@version command. Valet will install the specified PHP version via Homebrew if it is not already installed:

valet use php@8.1

valet use php

プロジェクトのルートに.valetrcファイルを作成することもできます。.valetrcファイルには、サイトで使用するPHPバージョンを指定する必要があります。You may also create a .valetrc file in the root of your project. The .valetrc file should contain the PHP version the site should use:

php=php@8.1

このファイルを作成したら、valet useコマンドを実行してください。コマンドはファイルを読み、サイトで優先するPHPバージョンを決めます。Once this file has been created, you may simply execute the valet use command and the command will determine the site's preferred PHP version by reading the file.

warning Warning! 複数のPHPバージョンをインストールしている場合でも、Valetは一度に一つのPHPバージョンのみを提供します。[!WARNING]
Valet only serves one PHP version at a time, even if you have multiple PHP versions installed.

データベースDatabase

アプリケーションにデータベースが必要な場合は、DBnginを確認してください。DBnginは、MySQL、PostgreSQL、およびRedisを含む無料のオールインワンデータベース管理ツールを提供します。DBnginをインストールした後、rootユーザー名とパスワードに空の文字列を使用して、127.0.0.1でデータベースに接続できます。If your application needs a database, check out DBngin[https://dbngin.com], which provides a free, all-in-one database management tool that includes MySQL, PostgreSQL, and Redis. After DBngin has been installed, you can connect to your database at 127.0.0.1 using the root username and an empty string for the password.

インストレーションのリセットResetting Your Installation

Valetインストレーションが正しく動作せずに問題が起きた時は、composer global require laravel/valetの後に、valet installを実行してください。これによりインストール済みのValetがリセットされ、さまざまな問題が解決されます。稀にValetを「ハードリセット」する必要がある場合もあり、その場合はvalet installの前にvalet uninstall --forceを実行してください。If you are having trouble getting your Valet installation to run properly, executing the composer global require laravel/valet command followed by valet install will reset your installation and can solve a variety of problems. In rare cases, it may be necessary to "hard reset" Valet by executing valet uninstall --force followed by valet install.

ValetのアップグレードUpgrading Valet

ターミナルでcomposer global require laravel/valetコマンドを実行すると、Valetのインストールを更新できます。アップグレード後、valet installコマンドを実行して、Valetが必要に応じて設定ファイルへ追加のアップグレードを行うことを推奨します。You may update your Valet installation by executing the composer global require laravel/valet command in your terminal. After upgrading, it is good practice to run the valet install command so Valet can make additional upgrades to your configuration files if necessary.

Valet4へのアップグレードUpgrading to Valet 4

Valet3からValet4へアップグレードするときは、Valetのインストールを以下の手順に従い、正しくアップグレードしてください。If you're upgrading from Valet 3 to Valet 4, take the following steps to properly upgrade your Valet installation:

  • サイトのPHP バージョンをカスタマイズするため、.valetphprcファイルを追加している場合は、各.valetphprcファイルを.valetrcへリネームしてください。次に、.valetrcファイルの既存の内容の前に、php=を追加します。If you've added .valetphprc files to customize your site's PHP version, rename each .valetphprc file to .valetrc. Then, prepend php= to the existing content of the .valetrc file.
  • 新しいドライバシステムの名前空間、拡張子、タイプヒント、戻り値タイプヒントが一致するように、カスタムドライバを更新してください。例としてValetのSampleValetDriverを参考にするとよいでしょう。Update any custom drivers to match the namespace, extension, type-hints, and return type-hints of the new driver system. You may consult Valet's SampleValetDriver[https://github.com/laravel/valet/blob/d7787c025e60abc24a5195dc7d4c5c6f2d984339/cli/stubs/SampleValetDriver.php] as an example.
  • PHP7.1~7.4をサイトで使用しているなら、主に使用するバージョンでなくてもPHP8.0以上のバージョンを確実にHomebrewでインストールしてください。Valetが自身のスクリプトの実行に、このバージョンを使用します。If you use PHP 7.1 - 7.4 to serve your sites, make sure you still use Homebrew to install a version of PHP that's 8.0 or higher, as Valet will use this version, even if it's not your primary linked version, to run some of its scripts.

サイト動作Serving Sites

Valetがインストールされると、Laravelアプリケーションの提供を開始する準備が整います。Valetは、アプリケーションの提供に役立つ2つのコマンドparklinkを提供しています。Once Valet is installed, you're ready to start serving your Laravel applications. Valet provides two commands to help you serve your applications: park and link.

parkコマンドThe park Command

parkコマンドは、アプリケーションを含むマシン上のディレクトリを登録します。ディレクトリがValetで「パーク」されると、そのディレクトリ内のすべてのディレクトリにWebブラウザのhttp://<directory-name>.testからアクセスできるようになります。The park command registers a directory on your machine that contains your applications. Once the directory has been "parked" with Valet, all of the directories within that directory will be accessible in your web browser at http://<directory-name>.test:

cd ~/Sites

valet park

これだけです。これで、「パークした」ディレクトリ内に作成したアプリケーションはすべて、「http://.test」規則を使用して自動的に提供されます。したがって、パーキングディレクトリに「laravel」という名前のディレクトリが含まれている場合、そのディレクトリ内のアプリケーションには``http://laravel.testからアクセスできます。付け加えて、Valetではワイルドカードのサブドメイン(http://foo.laravel.test`)を使ったアクセスも自動的に可能です。That's all there is to it. Now, any application you create within your "parked" directory will automatically be served using the http://<directory-name>.test convention. So, if your parked directory contains a directory named "laravel", the application within that directory will be accessible at http://laravel.test. In addition, Valet automatically allows you to access the site using wildcard subdomains (http://foo.laravel.test).

linkコマンドThe link Command

linkコマンドを使用してLaravelアプリケーションを提供することもできます。このコマンドは、ディレクトリ全体ではなく、ディレクトリ内の単一のサイトにサービスを提供する場合に役立ちます。The link command can also be used to serve your Laravel applications. This command is useful if you want to serve a single site in a directory and not the entire directory:

cd ~/Sites/laravel

valet link

linkコマンドを使用してアプリケーションがValetにリンクされると、そのディレクトリ名を使用してアプリケーションにアクセスできます。したがって、上記の例でリンクされたサイトは、http://laravel.testでアクセスできます。付け加えて、Valetではワイルドカードのサブドメイン(http://foo.laravel.test)を使ったアクセスも自動的に可能です。Once an application has been linked to Valet using the link command, you may access the application using its directory name. So, the site that was linked in the example above may be accessed at http://laravel.test. In addition, Valet automatically allows you to access the site using wildcard sub-domains (http://foo.laravel.test).

別のホスト名でアプリケーションを提供する場合は、ホスト名をlinkコマンドへ渡せます。たとえば、以下のコマンドを実行して、アプリケーションをhttp://application.testで利用できます。If you would like to serve the application at a different hostname, you may pass the hostname to the link command. For example, you may run the following command to make an application available at http://application.test:

cd ~/Sites/laravel

valet link application

もちろん、linkコマンドを使用してサブドメイン上のアプリケーションを提供することもできます。Of course, you may also serve applications on subdomains using the link command:

valet link api.application

linksコマンドを実行して、リンクされているすべてのディレクトリのリストを表示できます。You may execute the links command to display a list of all of your linked directories:

valet links

unlinkコマンドは、サイトへのシンボリックリンクを破棄できます。The unlink command may be used to destroy the symbolic link for a site:

cd ~/Sites/laravel

valet unlink

TLSによるサイト保護Securing Sites With TLS

デフォルトでは、ValetはHTTP経由でサイトへサービスを提供します。ただし、HTTP/2を使用して暗号化されたTLSを介してサイトにサービスを提供する場合は、secureコマンドを使用できます。たとえば、サイトがlaravel.testドメインでValetによって提供されている場合は、次のコマンドを実行してサイトを保護する必要があります。By default, Valet serves sites over HTTP. However, if you would like to serve a site over encrypted TLS using HTTP/2, you may use the secure command. For example, if your site is being served by Valet on the laravel.test domain, you should run the following command to secure it:

valet secure laravel

サイトを「保護解除」し、プレーンHTTPを介したトラフィックの提供に戻すには、unsecureコマンドを使用します。secureコマンドと同様に、このコマンドはセキュリティで保護しなくするホスト名を指定します。To "unsecure" a site and revert back to serving its traffic over plain HTTP, use the unsecure command. Like the secure command, this command accepts the hostname that you wish to unsecure:

valet unsecure laravel

デフォルトサイトの提供Serving a Default Site

時には、未知のtestドメインを訪問したときに、404の代わりに「デフォルト」サイトを提供するよう、Valetを設定したいことがあるかもしれません。これを実現するには、デフォルトサイトとして機能するサイトへのパスを含む ~/.config/valet/config.json設定ファイルへdefaultオプションを追加します。Sometimes, you may wish to configure Valet to serve a "default" site instead of a 404 when visiting an unknown test domain. To accomplish this, you may add a default option to your ~/.config/valet/config.json configuration file containing the path to the site that should serve as your default site:

"default": "/Users/Sally/Sites/example-site",

サイトごとのPHPバージョンPer-Site PHP Versions

Valetはサイトにサービスを提供するため、デフォルトでグローバルなPHPインストールを使用します。しかし、さまざまなサイトで複数のPHPバージョンをサポートする必要がある場合は、isolateコマンドを使用して、特定のサイトが使用するPHPバージョンを指定してください。isolateコマンドは、現在の作業ディレクトリにあるサイトに対し、Valetが指定したPHPバージョンを使用するように設定します。By default, Valet uses your global PHP installation to serve your sites. However, if you need to support multiple PHP versions across various sites, you may use the isolate command to specify which PHP version a particular site should use. The isolate command configures Valet to use the specified PHP version for the site located in your current working directory:

cd ~/Sites/example-site

valet isolate php@8.0

サイト名がそれを含むディレクトリ名と一致しない場合は、--siteオプションを使い、サイト名を指定します。If your site name does not match the name of the directory that contains it, you may specify the site name using the --site option:

valet isolate php@8.0 --site="site-name"

便利なように、valet phpcomposerwhich-phpコマンドはプロキシされ、サイトのPHPバージョンに応じて適切な PHP CLIやツールが呼び出されます。For convenience, you may use the valet php, composer, and which-php commands to proxy calls to the appropriate PHP CLI or tool based on the site's configured PHP version:

valet php
valet composer
valet which-php

個別のサイトとPHPバージョンの全一覧を表示するには、isolatedコマンドを実行してください。You may execute the isolated command to display a list of all of your isolated sites and their PHP versions:

valet isolated

サイトのPHPをValetのグローバルインストールしたPHPバージョンに戻すには、サイトのルートディレクトリで、unisolateコマンドを実行します。To revert a site back to Valet's globally installed PHP version, you may invoke the unisolate command from the site's root directory:

valet unisolate

サイト共有Sharing Sites

Valetは、ローカルサイトを世界へ公開し共有するコマンドも用意しており、モバイルデバイスでサイトをテストしたり、チームメンバーやクライアントと共有したりする簡単な方法を提供しています。Valet includes a command to share your local sites with the world, providing an easy way to test your site on mobile devices or share it with team members and clients.

はじめからValetは、ngrokやExposeを使ったサイトの共有に対応しています。サイトを共有する前に、share-toolコマンドを使用し、ngrokまたはexposeを指定して、Valetの設定を更新する必要があります。Out of the box, Valet supports sharing your sites via ngrok or Expose. Before sharing a site, you should update your Valet configuration using the share-tool command, specifying either ngrok or expose:

valet share-tool ngrok

選択したツールが、Homebrew(ngrokの場合)やComposer(Exposeの場合)を介して、まだインストールされていない場合、Valetは自動的にインストールするように促します。もちろん、どちらのツールでも、サイトの共有を開始する前に、ngrokもしくはExposeのアカウントを認証する必要があります。If you choose a tool and don't have it installed via Homebrew (for ngrok) or Composer (for Expose), Valet will automatically prompt you to install it. Of course, both tools require you to authenticate your ngrok or Expose account before you can start sharing sites.

サイトを共有するには、ターミナルでサイトのディレクトリに移動し、Valetのshareコマンドを実行します。パブリックからアクセス可能なURLがクリップボードにコピーされますので、ブラウザに直接貼り付けたり、チームと共有したりできます。To share a site, navigate to the site's directory in your terminal and run Valet's share command. A publicly accessible URL will be placed into your clipboard and is ready to paste directly into your browser or to be shared with your team:

cd ~/Sites/laravel

valet share

サイトの共有を停止するには、Control Cキーを押してください。To stop sharing your site, you may press Control C.

warning Warning! カスタムDNSサーバ(1.1.1.1など)を使用している場合、ngrok共有が正しく動作しないかもしれません。このような場合は、Macのシステム設定を開き、ネットワーク設定へ行き、詳細設定を開き、DNSタブを開き、最初のDNSサーバとして127.0.0.1を追加します。[!WARNING]
If you're using a custom DNS server (like 1.1.1.1), ngrok sharing may not work correctly. If this is the case on your machine, open your Mac's system settings, go to the Network settings, open the Advanced settings, then go the DNS tab and add 127.0.0.1 as your first DNS server.

Ngrokを使うサイト共有Sharing Sites via Ngrok

ngrokを使用してサイトを共有するには、ngrokアカウントの作成認証トークンの設定が必要です。認証トークンを取得したら、そのトークンを使ってValetの設定を更新できます。Sharing your site using ngrok requires you to create an ngrok account[https://dashboard.ngrok.com/signup] and set up an authentication token[https://dashboard.ngrok.com/get-started/your-authtoken]. Once you have an authentication token, you can update your Valet configuration with that token:

valet set-ngrok-token YOUR_TOKEN_HERE

lightbulb Note: valet share --region=euのように、共有コマンドに追加のngrokパラメータを渡せます。詳しくは、ngrokのドキュメントを参照してください。[!NOTE]
You may pass additional ngrok parameters to the share command, such as valet share --region=eu. For more information, consult the ngrok documentation[https://ngrok.com/docs].

Exposeを使うサイト共有Sharing Sites via Expose

Exposeを使ってサイトを共有するには、Exposeアカウントの作成認証トークンによるExposeへの認証が必要です。Sharing your site using Expose requires you to create an Expose account[https://expose.dev/register] and authenticate with Expose via your authentication token[https://expose.dev/docs/getting-started/getting-your-token].

Exposeがサポートしている追加のコマンドラインパラメータに関する情報は、Exposeのドキュメントを参照してください。You may consult the Expose documentation[https://expose.dev/docs] for information regarding the additional command-line parameters it supports.

ローカルネットワークでのサイト共有Sharing Sites on Your Local Network

Valetは、開発マシンがインターネットからのセキュリティリスクにさらされないように、デフォルトで内部の127.0.0.1インターフェイスへの受信トラフィックを制限します。Valet restricts incoming traffic to the internal 127.0.0.1 interface by default so that your development machine isn't exposed to security risks from the Internet.

ローカルネットワーク上の他のデバイスが自分のマシンのIPアドレス(例:192.168.1.1.10/application.test)を介して自分のマシン上のValetサイトにアクセスできるようにしたい場合は、そのサイトの適切なNginx設定ファイルを手作業で編集してlistenディレクティブの制限を取り除く必要があります。ポート80と443のlistenディレクティブのプレフィックス127.0.0.0.1:を削除する必要があります。If you wish to allow other devices on your local network to access the Valet sites on your machine via your machine's IP address (eg: 192.168.1.10/application.test), you will need to manually edit the appropriate Nginx configuration file for that site to remove the restriction on the listen directive. You should remove the 127.0.0.1: prefix on the listen directive for ports 80 and 443.

プロジェクトでvalet secureを実行していない場合は、/usr/local/etc/nginx/valet/valet.confファイルを編集し、HTTPSではないサイトへのネットワークアクセスを開けます。あるサイトに対しvalet secureを実行することで、HTTPSにてプロジェクトサイトを動かしている場合は、~/.config/valet/Nginx/app-name.testファイルを編集する必要があります。If you have not run valet secure on the project, you can open up network access for all non-HTTPS sites by editing the /usr/local/etc/nginx/valet/valet.conf file. However, if you're serving the project site over HTTPS (you have run valet secure for the site) then you should edit the ~/.config/valet/Nginx/app-name.test file.

Nginx設定を更新したら、設定の変更を反映するためにvalet restartコマンドを実行してください。Once you have updated your Nginx configuration, run the valet restart command to apply the configuration changes.

サイト限定環境変数Site Specific Environment Variables

他のフレームワークを使用する一部のアプリケーションは、サーバ環境変数に依存する場合がありますが、それらの変数をプロジェクト内で設定する方法を提供しません。Valetを使用すると、プロジェクトのルート内に.valet-env.phpファイルを追加することにより、サイト固有の環境変数を設定できます。このファイルは、配列で指定する各サイトのグローバル$_SERVER配列へ追加するサイト/環境変数のペアの配列を返す必要があります。Some applications using other frameworks may depend on server environment variables but do not provide a way for those variables to be configured within your project. Valet allows you to configure site specific environment variables by adding a .valet-env.php file within the root of your project. This file should return an array of site / environment variable pairs which will be added to the global $_SERVER array for each site specified in the array:

<?php

return [
    // laravel.testサイトの$_SERVER['key']を"value"へ設定
    'laravel' => [
        'key' => 'value',
    ],

    // すべてのサイトで$_SERVER['key']を"value"へ設定
    '*' => [
        'key' => 'value',
    ],
];

プロキシサーバProxying Services

時にローカルマシンの他のサービスへValetドメインをプロキシ動作させたいこともあるでしょう。たとえば、Valetを実行する一方で、たまにDockerにより別のサイトを実行する必要がある場合です。しかし、ValetとDockerは同時に80ポートを両方でバインドできません。Sometimes you may wish to proxy a Valet domain to another service on your local machine. For example, you may occasionally need to run Valet while also running a separate site in Docker; however, Valet and Docker can't both bind to port 80 at the same time.

これを解決するには、proxyコマンドを使いプロキシを生成してください。たとえば、http://elasticsearch.testからのトラフィックをすべてhttp://127.0.0.1:9200へ仲介するには、以下のとおりです。To solve this, you may use the proxy command to generate a proxy. For example, you may proxy all traffic from http://elasticsearch.test to http://127.0.0.1:9200:

# Proxy over HTTP...
valet proxy elasticsearch http://127.0.0.1:9200

# Proxy over TLS   HTTP/2...
valet proxy elasticsearch http://127.0.0.1:9200 --secure

unproxyコマンドでプロキシを削除できます。You may remove a proxy using the unproxy command:

valet unproxy elasticsearch

proxiesコマンドを使用して、プロキシするすべてのサイト設定を一覧表示できます。You may use the proxies command to list all site configurations that are proxied:

valet proxies

カスタムValetドライバCustom Valet Drivers

独自のValet「ドライバ」を作成して、ValetがネイティブにサポートしていないフレームワークやCMSで実行するPHPアプリケーションを提供できます。Valetをインストールすると、SampleValetDriver.phpファイルを含む〜/.config/valet/Driversディレクトリが作成されます。このファイルには、カスタムドライバの作成方法を示すサンプルドライバ実装が含まれています。ドライバを作成するには、servesisStaticFile、およびfrontControllerPathの3つのメソッドを実装するだけです。You can write your own Valet "driver" to serve PHP applications running on a framework or CMS that is not natively supported by Valet. When you install Valet, a ~/.config/valet/Drivers directory is created which contains a SampleValetDriver.php file. This file contains a sample driver implementation to demonstrate how to write a custom driver. Writing a driver only requires you to implement three methods: serves, isStaticFile, and frontControllerPath.

全3メソッドは$sitePath$siteName$uriを引数で受け取ります。$sitePathは、/Users/Lisa/Sites/my-projectのように、サイトプロジェクトへのフルパスです。$siteNameは"ホスト" / "サイト名"記法のドメイン(my-project)です。$uriはやって来たリクエストのURI(/foo/bar)です。All three methods receive the $sitePath, $siteName, and $uri values as their arguments. The $sitePath is the fully qualified path to the site being served on your machine, such as /Users/Lisa/Sites/my-project. The $siteName is the "host" / "site name" portion of the domain (my-project). The $uri is the incoming request URI (/foo/bar).

カスタムValetドライバが完成したら、FrameworkValetDriver.php命名規則を使用して〜/.config/valet/Driversディレクトリに配置します。たとえば、WordPress用のカスタムバレットドライバを作成している場合、ファイル名はWordPressValetDriver.phpである必要があります。Once you have completed your custom Valet driver, place it in the ~/.config/valet/Drivers directory using the FrameworkValetDriver.php naming convention. For example, if you are writing a custom valet driver for WordPress, your filename should be WordPressValetDriver.php.

カスタムValetドライバで実装する各メソッドのサンプルコードを見ていきましょう。Let's take a look at a sample implementation of each method your custom Valet driver should implement.

servesメソッドThe serves Method

servesメソッドは、そのドライバがやって来たリクエストを処理すべき場合に、trueを返してください。それ以外の場合はfalseを返してください。そのためには、メソッドの中で、渡された$sitePathの内容が、動作させようとするプロジェクトタイプを含んでいるかを判定します。The serves method should return true if your driver should handle the incoming request. Otherwise, the method should return false. So, within this method, you should attempt to determine if the given $sitePath contains a project of the type you are trying to serve.

たとえば、WordPressValetDriverを書いていると仮定してみましょう。servesメソッドは次のようになります。For example, let's imagine we are writing a WordPressValetDriver. Our serves method might look something like this:

/**
 * このドライバでリクエストを処理するか決める
 */
public function serves(string $sitePath, string $siteName, string $uri): bool
{
    return is_dir($sitePath.'/wp-admin');
}

isStaticFileメソッドThe isStaticFile Method

isStaticFileはリクエストが画像やスタイルシートのような「静的」なファイルであるかを判定します。ファイルが静的なものであれば、そのファイルが存在するディスク上のフルパスを返します。リクエストが静的ファイルでない場合は、falseを返します。The isStaticFile should determine if the incoming request is for a file that is "static", such as an image or a stylesheet. If the file is static, the method should return the fully qualified path to the static file on disk. If the incoming request is not for a static file, the method should return false:

/**
 * リクエストが静的なファイルであるかを判定する
 *
 * @return string|false
 */
public function isStaticFile(string $sitePath, string $siteName, string $uri)
{
    if (file_exists($staticFilePath = $sitePath.'/public/'.$uri)) {
        return $staticFilePath;
    }

    return false;
}

warning Warning! isStaticFileメソッドは、リクエストのURIが/ではなく、servesメソッドでtrueが返された場合のみ呼びだされます。[!WARNING]
The isStaticFile method will only be called if the serves method returns true for the incoming request and the request URI is not /.

frontControllerPathメソッドThe frontControllerPath Method

frontControllerPathメソッドは、アプリケーションの「フロントコントローラ」への完全修飾パスを返す必要があります。これは通常、「index.php」ファイルまたは同等のものです。The frontControllerPath method should return the fully qualified path to your application's "front controller", which is typically an "index.php" file or equivalent:

/**
 * アプリケーションのフロントコントローラへの絶対パスの取得
 */
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
{
    return $sitePath.'/public/index.php';
}

ローカルドライバLocal Drivers

単一のアプリケーション用にカスタムValetドライバを定義する場合は、アプリケーションのルートディレクトリにLocalValetDriver.phpファイルを作成します。カスタムドライバは、基本のValetDriverクラスを拡張するか、LaravelValetDriverなどの既存のアプリケーション固有のドライバを拡張する場合があります。If you would like to define a custom Valet driver for a single application, create a LocalValetDriver.php file in the application's root directory. Your custom driver may extend the base ValetDriver class or extend an existing application specific driver such as the LaravelValetDriver:

use Valet\Drivers\LaravelValetDriver;

class LocalValetDriver extends LaravelValetDriver
{
    /**
     * リクエストに対し、このドライバを動作させるかを決める
     */
    public function serves(string $sitePath, string $siteName, string $uri): bool
    {
        return true;
    }

    /**
     * アプリケーションのフロントコントローラに対する完全な解決済みパスを取得する
     */
    public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
    {
        return $sitePath.'/public_html/index.php';
    }
}

その他のValetコマンドOther Valet Commands

コマンドCommand 説明Description
valet listvalet list 全Valetコマンドの一覧を表示します。Display a list of all Valet commands.
valet diagnosevalet diagnose Valetのデバッグを支援するための診断結果を出力します。Output diagnostics to aid in debugging Valet.
valet directory-listingvalet directory-listing ディレクトリ一覧の動作を決定します。デフォルトは "off "で、ディレクトリに対して404ページを表示します。Determine directory-listing behavior. Default is "off", which renders a 404 page for directories.
valet forgetvalet forget "park"された(サイト検索の親ディレクトリとして登録された)ディレクトリでこのコマンドを実行し、サイト検索対象のディレクトリリストから外します。Run this command from a "parked" directory to remove it from the parked directory list.
valet logvalet log Valetサービスにより書き込まれたログリストを表示します。View a list of logs which are written by Valet's services.
valet pathsvalet paths "park"されたすべてのパスを表示します。View all of your "parked" paths.
valet restartvalet restart Valetデーモンをリスタートします。Restart the Valet daemons.
valet startvalet start Valetデーモンをスタートします。Start the Valet daemons.
valet stopvalet stop Valetデーモンを停止します。Stop the Valet daemons.
valet trustvalet trust Valetコマンド実行でパスワード入力をしなくて済むように、BrewとValetへsudoersファイルを追加します。Add sudoers files for Brew and Valet to allow Valet commands to be run without prompting for your password.
valet uninstallvalet uninstall Valetをアンインストールします。手作業で削除する場合のインストラクションを表示します。--forceパラメータを指定した場合は、Valetすべてを強制的に削除します。Uninstall Valet: shows instructions for manual uninstall. Pass the --force option to aggressively delete all of Valet's resources.

ValetのディレクトリとファイルValet Directories and Files

Valet環境の問題のトラブルシューティングを行う際に、次のディレクトリとファイルの情報が役立つでしょう。You may find the following directory and file information helpful while troubleshooting issues with your Valet environment:

~/.config/valet~/.config/valet

Valetのすべての設定が含まれます。定期的にこのディレクトリをバックアップすることを推奨します。Contains all of Valet's configuration. You may wish to maintain a backup of this directory.

~/.config/valet/dnsmasq.d/~/.config/valet/dnsmasq.d/

このディレクトリは、DNSMasq設定を保存しています。This directory contains DNSMasq's configuration.

~/.config/valet/Drivers/~/.config/valet/Drivers/

このディレクトリは、Valetのドライバを保存しています。ドライバは、特定のフレームワーク/CMSをどのように提供するかを決めています。This directory contains Valet's drivers. Drivers determine how a particular framework / CMS is served.

~/.config/valet/Nginx/~/.config/valet/Nginx/

このディレクトリは、ValetのNginxサイト設定をすべて保存しています。ディレクトリ内のファイルは、installsecureコマンドを実行すると再構築されます。This directory contains all of Valet's Nginx site configurations. These files are rebuilt when running the install and secure commands.

~/.config/valet/Sites/~/.config/valet/Sites/

このディレクトリには、リンクしたプロジェクトのすべてのシンボリックリンクが保存されます。This directory contains all of the symbolic links for your linked projects[#the-link-command].

~/.config/valet/config.json~/.config/valet/config.json

このファイルは、Valetのマスター設定ファイルです。This file is Valet's master configuration file.

~/.config/valet/valet.sock~/.config/valet/valet.sock

このファイルは、ValetのNginxインストールが使用するPHP-FPMソケットです。これは、PHPが正しく実行されている場合にのみ存在します。This file is the PHP-FPM socket used by Valet's Nginx installation. This will only exist if PHP is running properly.

~/.config/valet/Log/fpm-php.www.log~/.config/valet/Log/fpm-php.www.log

このファイルは、PHPエラーのユーザーログです。This file is the user log for PHP errors.

~/.config/valet/Log/nginx-error.log~/.config/valet/Log/nginx-error.log

このファイルは、Nginxエラーのユーザーログです。This file is the user log for Nginx errors.

/usr/local/var/log/php-fpm.log/usr/local/var/log/php-fpm.log

このファイルは、PHP-FPMエラーのシステムログです。This file is the system log for PHP-FPM errors.

/usr/local/var/log/nginx/usr/local/var/log/nginx

このディレクトリは、Nginxアクセスログとエラーログを保存します。This directory contains the Nginx access and error logs.

/usr/local/etc/php/X.X/conf.d/usr/local/etc/php/X.X/conf.d

このディレクトリには、さまざまなPHP設定設定用の*.iniファイルが含まれています。This directory contains the *.ini files for various PHP configuration settings.

/usr/local/etc/php/X.X/php-fpm.d/valet-fpm.conf/usr/local/etc/php/X.X/php-fpm.d/valet-fpm.conf

このファイルは、PHP-FPMプール設定ファイルです。This file is the PHP-FPM pool configuration file.

~/.composer/vendor/laravel/valet/cli/stubs/secure.valet.conf~/.composer/vendor/laravel/valet/cli/stubs/secure.valet.conf

このファイルは、サイトのSSL証明書を構築するために使用するデフォルトのNginx設定です。This file is the default Nginx configuration used for building SSL certificates for your sites.

ディスクアクセスDisk Access

macOS 10.14以降、一部のファイルやディレクトリへのアクセスがデフォルトで制限されます。この制限には、デスクトップ、ドキュメント、およびダウンロードの各ディレクトリが含まれます。さらに、ネットワークボリュームとリムーバブルボリュームへのアクセスも制限されています。したがって、Valetでは、サイトフォルダをこれらの保護された場所の外に配置することを推奨します。Since macOS 10.14, access to some files and directories is restricted by default[https://manuals.info.apple.com/MANUALS/1000/MA1902/en_US/apple-platform-security-guide.pdf]. These restrictions include the Desktop, Documents, and Downloads directories. In addition, network volume and removable volume access is restricted. Therefore, Valet recommends your site folders are located outside of these protected locations.

しかし、これらのロケーションの中からサイトを提供したい場合、Nginxに「フルディスクアクセス」を与える必要があります。そうしないと、特に静的アセットを提供する際に、Nginxからサーバエラーやその他の予測不可能な動作が発生する可能性があります。通常macOSは自動的に、Nginxへこれらの場所へのフルアクセスを許可するよう促します。もしくは、システム環境設定 > セキュリティとプライバシー > プライバシーから、ディスクへのフルアクセスを選択することもできます。次に、メインウィンドウにある nginx エントリを有効にします。However, if you wish to serve sites from within one of those locations, you will need to give Nginx "Full Disk Access". Otherwise, you may encounter server errors or other unpredictable behavior from Nginx, especially when serving static assets. Typically, macOS will automatically prompt you to grant Nginx full access to these locations. Or, you may do so manually via System Preferences > Security & Privacy > Privacy and selecting Full Disk Access. Next, enable any nginx entries in the main window pane.

章選択

設定

明暗テーマ
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!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

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

コードフォント

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

保存内容リセット

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

ヘッダー項目移動

キーボード操作