Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created December 27, 2011 21:29
Show Gist options
  • Save JeffreyWay/1525217 to your computer and use it in GitHub Desktop.
Save JeffreyWay/1525217 to your computer and use it in GitHub Desktop.
Instant Server for Current Directory
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
@wenerme
Copy link

wenerme commented May 21, 2015

My universal version, works with npm, python, php and can run under windows, linux and mac

# Instant Server for Current Directory
# https://gist.github.com/JeffreyWay/1525217
function server()
{
    local port=${1:-8000}
    iscmd python && {
        (sleep 1 && o "http://localhost:${port}/")&
        python -m SimpleHTTPServer ${port}
    }

    iscmd npm && (npm -g ls --depth=0 | grep server@) >/dev/null && {
        # Use npm server
        (sleep 1 && o "http://localhost:${port}/")&
        server ${port}
    }

    iscmd php && {
        (sleep 1 && o "http://localhost:${port}/")&
        php -S localhost:${port}
    }
}

Also in my dotfiles. the iscmd is defined in my dotfiles too.

@AustinMaddox
Copy link

What about running a PHP built-in development server in a Docker container?

server() {
  local port="${1:-8000}"
  local path="${2:-.}"
  (sleep 1 && open "http://localhost:${port}")&
  docker run --rm --interactive --tty --name="php-built-in-development-web-server-$port" --publish $port:$port --network="local-network" --volume "$PWD":/usr/src/myapp --workdir /usr/src/myapp --user $(id -u):$(id -g) php:7.2-alpine php -S 0.0.0.0:$port -t $path
}

Portable 😄 You don't really have to worry about Windows, Mac, Linux if it is running in Docker. 🐳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment