LoginSignup
58
47

More than 5 years have passed since last update.

Macで簡易ローカルサーバーをたてる

Last updated at Posted at 2016-06-30

普段、gulpとBrowser-Syncを使って構築をしていますが、
わざわざ、Browser-Syncの環境を作る必要のない時などに、サクっとローカルサーバを立てたい時の方法です。

ローカルサーバをたてる

1. ターミナルを開く
2. ドキュメントルート(表示させたい)にcdで移動
3. [python -m SimpleHTTPServer 8888]を実行
4. [http://localhost:8888/](http://localhost:8888/)

pythonコマンド、一行だけ。これだけです。超簡単。
サルでもできますね。(私はサル以下ですが。。)

ちなみにポートは変更可能です。 (例) 8888 → 7777

サンプル

サンプルのファイルを用意する。

(ドキュメントルート)
/Users/(ユーザー名)/sample/index.html

用意したファイル

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>hogehoge</title>
</head>
<body>
  <h1>pythonコマンドで簡易ローカルサーバーをたてる</h1>
  <p>サルでもできる。</p>
</body>
</html>

ターミナルでドキュメントルートへ移動

$ cd /Users/(ユーザー名)/sample

pythonコマンド実行

$ python -m SimpleHTTPServer 8888

ブラウザ確認

[http://localhost:8888/](http://localhost:8888/)

1.jpg


サーバーを停止する

[control] + [c]
58
47
2

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
58
47