LoginSignup
10
16

More than 3 years have passed since last update.

php ビルトインサーバーで開発

Last updated at Posted at 2017-07-30

PHP ビルとインサーバーでローカル開発環境を構築

下記サイトにこのような説明があります。

PHP 5.4.0 から、CLI SAPI にはウェブサーバーの機能が組み込まれるようになりました。

このウェブサーバーは単一のシングルスレッドプロセスしか実行しないので、 リクエストがブロックされると、PHP アプリケーションはストールします。

URI リクエストの処理は、PHP を開始した時点の作業ディレクトリから行われます。 -t オプションを使えば、ドキュメントルートを明示的に指定することができます。 URI リクエストにファイルが含まれない場合は、指定したディレクトリにある index.php あるいは index.html を返します。どちらも存在しない場合は、 親ディレクトリにさかのぼって index.php と index.html を探します。 どちらか一方が見つかるか、あるいはドキュメントルートに達するまでこれが続きます。 index.php あるいは index.html が見つかるとそれを返し、 $_SERVER['PATH_INFO'] が URI の末尾にセットされます。 見つからなかった場合はレスポンスコード 404 を返します。

使い方

下記の方法で通常起動

php -S localhost:8000

下記の方法がドキュメントルートを指定しての起動

php -S localhost:8000 -t /Users/username/Documents/Devlop/
PHP 5.6.30 Development Server started at Sun Jul 30 20:30:35 2017
Listening on http://localhost:8080
Document root is 
/Users/username/Documents/Devlop/
Press Ctrl-C to quit.

control C で停止

10
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
16