Last active
December 12, 2018 01:45
-
-
Save samhk222/00a1c3b2913e819d54a9ca4ea59096e8 to your computer and use it in GitHub Desktop.
Blog - Post sobre variáveis .env
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
composer require vlucas/phpdotenv |
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
# Cria o arquivo vazio. | |
touch .env.dist | |
# Adicione a pasta vendor e o .env no seu .gitignore para não ser comitado no repositório. | |
echo "/vendor/*" > .gitignore | |
echo ".env" >> .gitignore | |
# Edite o .env.dist no sublime (ou seu editor predileto) | |
subl .env.dist | |
# Após a edição do arquivo, copie ele para o .env (gerando dessa forma o arquivo) | |
cp .env.dist .env |
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
<?PHP | |
require('vendor/autoload.php'); | |
$dotenv = new Dotenv\Dotenv(__DIR__); | |
$dotenv->load(); | |
echo "\n<pre>Todas as variáveis de ambiente\n"; | |
print_r($_ENV); | |
echo "\nPara pegar uma variável específica\n"; | |
echo sprintf("Nome do banco de dados:%s", getenv('DB_DATABASE')); | |
echo "\n</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment