How to easily start a webserver in any folder?

Solution 1:

Use

python2 -m SimpleHTTPServer 80

or

python3 -m http.server 80

to start a simple HTTP server.

Replace 80 with another number if you want it to listen on a different port. For ports < 1024 it needs to run with root privileges.

Solution 2:

I also like to use PHP for this purpose, as it enables me to run stuff like WordPress on the fly and develop themes more easily (you still need MySQL, though):

php -S 0.0.0.0:8000

In the same script that starts this I also start guard, which auto-refreshes the browser on file change.

Solution 3:

if you are more ruby minded, the serve gem is great

serve

or for i different port:

serve 9000

install with gem install serve

Solution 4:

This is also possible in Ruby without installing a gem.

ruby -run -e httpd . -p5000