Blog - Post sobre variáveis .env
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
composer require vlucas/phpdotenv |
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
# 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 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