Laravel(6.x) php artisan serveのオプション色々
Laravelのartisanコマンドの1つサーバ起動serveコマンドについて
基本的には php artisan serve
で事足りると思いますが
他のオプションについて調べてみたので使い方含め
まとめておきたいと思います
まずはヘルプ --help
で確認します
php artisan serve --help
$ php artisan serve --help
Description:
Serve the application on the PHP development server
Usage:
serve [options]
Options:
--host[=HOST] The host address to serve the application on [default: "127.0.0.1"]
--port[=PORT] The port to serve the application on
--tries[=TRIES] The max number of ports to attempt to serve from [default: 10]
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
色々なオプションがありますが、主に使うのは --host
と --port
です
ホスト名を変更
デフォルトでは 127.0.0.1
で自分自身のIP、つまりlocalhostとなっています
ローカル環境で確認検証する分にはこれで十分ですが
例えばサーバ用のマシンで立ち上げたものに対して別のマシンから
アクセスしたいといった場合にはこのままではアクセスできません
そういった場合は 0.0.0.0
を指定して別マシンからでも
アクセスできるようにします
php artisan serve --host=0.0.0.0
ポート番号を変更
ポート番号は php artisan serveでphpのビルトインサーバを起動
すると 8000
がデフォルトで採用されます
httpポートの80や8080などで起動させたい、それ以外に9999など
独自に決めたポートで起動させたいといった場合
php artisan serve --port=8080
まとめ
artisanコマンドは非常に便利ですがとても多く、またオプションも多くあり
迷うと思います
今回はphpビルトインサーバを起動させるserve について
主に使うユースケースを紹介しました