cwrdjw
Last Updated: February 25, 2016
·
981
· futuraprime

Easy access to a web server

Python's SimpleHTTPServer is a really easy way to get a localhost up and running. Just type:

python -m SimpleHTTPServer 8888

and your current working directory is running a server at http://localhost:8888/. But typing that is tedious—here's how to make it an alias instead (on a Mac/UNIX install).

echo "alias pysrv='python -m SimpleHTTPServer'" >> ~/.bash_profile
source ~/.bash_profile

Now, you can just type

pysrv 8888

and get a web server. Much easier to remember!

(NOTE: ~/.bashrc is a more traditional place for this, but a default OS X setup has no ~/.bashrc file. If you have one, put the alias there instead of ~/.bash_profile)

3 Responses
Add your response

2849

Python 3 is simpler: "python -m http.server 8888".
I agree with you that the SimpleHTTPServer Lower and Upper cases are difficult to remember.

over 1 year ago ·
2855

That python server is cliche for me :) Also touch is not necessary.

over 1 year ago ·
3884

See my tip on how to easily start python's webserver from Nautilus: Simple HTTP server from Nautilus context menu

over 1 year ago ·