Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann
Last active December 27, 2015 18:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maxhoffmann/7373563 to your computer and use it in GitHub Desktop.
Save maxhoffmann/7373563 to your computer and use it in GitHub Desktop.
run local php server and open browser
# local PHP Server
server() {
url="localhost:${2:-8000}"
if [ -z "$1" ]; then
php -S $url & # run server in background
else
php -S $url -t $1 &
fi
sleep 0.3s # wait for server to start
open http://$url # open browser
fg # back to server process
}
# Usage:
# server {directory} {port}
#
# default directory is the current one
# default port is 8000
# PHP’s built-in server is avaible since version 5.4 (pre-installed on Mavericks)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment