Last active
December 27, 2015 18:59
run local php server and open browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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