Sunday , 30 April 2017

5+ Handy HTTP Web servers for Development

Working on PHP, Python, Node.js, Ruby. These simple commands will spin a local webserver for you in seconds. Some we don’t need to start entire server setup to run some simple tests or snippets. In such cases this is very useful.

PHP

This command will work only on PHP 5.4+ versions. At the site root directory, Run php -v on your terminal / command prompt to check php version.

Local server will be available at http://127.0.0.1:8000

 

# Required PHP 5.4+ $ php -S 127.0.0.1:8000

 

Python

If you use Python 2.x version you can use SimpleHTTPServer to start a webserver. Local server will be available at http://127.0.0.1:8000.

 

$ python -m SimpleHTTPServer 8000

 

For Python 3.x versions:

 

$ python -m http.server 8000

 

Node.js

 

In node.js you need to install http server modules like “http-server” or “serve” to run a static http server. Install the dependency and run the command from the project root directory.

Local server will be available at http://127.0.0.1:8000

 

#Install Dependency $ npm install http-server -g $ http-server -p 8000

 

#Install Dependency $ npm install -g serve $ serve -p 8000

 

Ruby

 

In Ruby you can use webrick to start a local http server. run the command from the site root directory. Local server will be available at http://127.0.0.1:8000

 

$ ruby -rwebrick -e’WEBrick::HTTPServer.new(:Port => 8000, :DocumentRoot => Dir.pwd).start’

 

For Ruby 1.9.2+ versions you can simply use the below command.

 

$ ruby -run -ehttpd . -p8000

 

 

 

Check Also

Building Faster Mobile Websites

the nuts and bolts of hitting the 1000 millisecond “time to glass” target …