-
-
Save dandelauro/320d090f08d73260a9b0226d4b3abf68 to your computer and use it in GitHub Desktop.
using .env files and basic rewrite with the built-in php server
This file contains 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
# add your env variables | |
DATABASE_HOST='127.0.0.1' | |
DATABASE_USER='root' | |
DATABASE_PASS='root' | |
DATABASE_NAME='database_name' |
This file contains 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
# 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'; | |
} |
This file contains 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
#!/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