Skip to content

Instantly share code, notes, and snippets.

@Radagaisus
Created May 21, 2013 23:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Radagaisus/5624075 to your computer and use it in GitHub Desktop.
Save Radagaisus/5624075 to your computer and use it in GitHub Desktop.
Starts a PHP or a Python server on a directory
# Stolen from a famous dotfile
# Start an HTTP server from a directory, optionally specifying the port
function server() {
local port="${1:-8000}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
}
# Start a PHP server from a directory, optionally specifying the port
# (Requires PHP 5.4.0+.)
function phpserver() {
local port="${1:-4000}"
local ip=$(ipconfig getifaddr en1)
sleep 1 && open "http://${ip}:${port}/" &
php -S "${ip}:${port}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment