Zhongde Liu

This is my personal "Clipboard" of web development stuff I come across


2 Comments

Create/start a simple local HTTP Server

In order to develop or test some static code, without copying them into your apache webroot or something else, you easily can start a simple static webserver within the directory you are currently in with following tools.
Because you sometimes you just need a http:// (likely localhost) Url instead of a file://… one.

  1. If you have Python (https://www.python.org/) installed you can start a static web server with following command, depending on the installed version.
    python -m SimpleHTTPServer [port]//python2
    python3 -m http.server [port]//python3
  2. If you have PHP > 5.4.0 (http://php.net/) installed you can start one with:
    php -S localhost:[port]
  3. Using Ruby (https://www.ruby-lang.org/) you setup a simple server with this command:
    ruby -run -e httpd . -p [port]
  4. For node.js (http://nodejs.org/) I use the  “simple, zero-configuration command-line http server” package (https://www.npmjs.org/package/http-server).
    After the default npm installation

    npm install http-server -g

    you just type

    http-server -p[port]

    into your console.

These are some nifty tools (or “oneliners“), when it comes to browse a static/client app/website/file with your browser in your local environment without copying the files somewhere else.