Skip to content

Instantly share code, notes, and snippets.

@dandelauro
Last active April 23, 2016 00:24
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 dandelauro/320d090f08d73260a9b0226d4b3abf68 to your computer and use it in GitHub Desktop.
Save dandelauro/320d090f08d73260a9b0226d4b3abf68 to your computer and use it in GitHub Desktop.
using .env files and basic rewrite with the built-in php server
# add your env variables
DATABASE_HOST='127.0.0.1'
DATABASE_USER='root'
DATABASE_PASS='root'
DATABASE_NAME='database_name'
# place this in your /public folder
if (!isset($_SERVER['DATABASE_HOST'])) {
$lines = file("../.env");
foreach ($lines as $line) {
if (strpos($line, "#") === false && strpos($line, "=") !== false) {
$vars = explode("=",$line);
$_SERVER[$vars[0]] = preg_replace("/'/", '', trim($vars[1]));
}
}
}
if (file_exists(__DIR__ . '/' . parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH))) {
return false;
} else {
include_once 'index.php';
}
#!/bin/bash
# place this in your project root
# running `server` in the termial fires things up
pushd public > /dev/null
php -d variables_order=EGPCS -S localhost:9000 .router
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment