Skip to content

Instantly share code, notes, and snippets.

@FaHuSchmidt
Created November 4, 2017 10:19
Show Gist options
  • Save FaHuSchmidt/819ad82d98040d1170878763303d7165 to your computer and use it in GitHub Desktop.
Save FaHuSchmidt/819ad82d98040d1170878763303d7165 to your computer and use it in GitHub Desktop.
wrapper script for serving a symfony application with docker

This script can be used to serv a symfony application at your current work dir without the need of having php installed locally.

The only requirement is a running Docker instance.

Basic usage:

Uses 8000 as public port and my-project as container name.

./run

Use another public port:

./run -p 8001

Use another name for container:

./run -n great-project

Further informations on configuring php command can be found at https://hub.docker.com/_/php/.

#!/usr/bin/env bash
while getopts p:n: option
do
case "${option}"
in
p) ARG_PORT=${OPTARG};;
n) ARG_NAME=${OPTARG};;
esac
done
PORT=${ARG_PORT:-8000}
NAME=${ARG_NAME:-"my-project"}
docker rm -f $NAME
docker run -d -p $PORT:80 \
--name $NAME \
-v "$PWD":/var/www/app \
-w /var/www/app \
php:alpine \
php -S 0.0.0.0:80 -t ./public ./public/index.php
echo "Open http://localhost:$PORT in your browser"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment