Start a static HTTP web server


Did you know it’s easy to start an HTTP web server using some of your favorite programming languages?

Prerequisites

Create a directory with an HTML file:

mkdir static
cd static
echo "<h1>Hello, world!</h1>" > index.html

Python

Python 3:

python3 -m http.server

Python 2:

python -m SimpleHTTPServer

View your webpage at localhost:8000. To specify the port, pass the port number in the next argument:

python3 -m http.server 1337
python -m SimpleHTTPServer 1337

Node.js

http-server:

npm install --global http-server
http-server

Or:

npx http-server

View your webpage at localhost:8080. To specify the port, use the -p flag:

http-server -p 1337

Ruby

ruby -run -e httpd .

View your webpage at localhost:8080. To specify the port, use the -p flag:

ruby -run -e httpd . -p 1337

PHP

php -S localhost:8000

View your webpage at localhost:8000. To specify the port, replace the port number in the command:

php -S localhost:1337


Please support this site and join our Discord!