Questions tagged [phpdotenv]

PHP dotenv is a PHP library that loads environment variables from a text file named .env for easy access from PHP code. This library is based on the Ruby gem (see [ruby-dotenv] tag.) There is also a Node.js module (see [dotenv] tag.)

Loads environment variables from .env to getenv(), $_ENV and $_SERVER automagically.

Code repository: https://github.com/vlucas/phpdotenv

Packagist page: https://packagist.org/packages/vlucas/phpdotenv

83 questions
173
votes
25 answers

Laravel not reading changes to .env file

After upgrading to Laravel 5.2, none of my .env file values are being read. I followed the upgrade instructions; none of my config files were changed except auth.php. They were all working fine in previous version, 5.1.19 .env contains values such…
andrewtweber
  • 24,520
  • 22
  • 88
  • 110
144
votes
13 answers

Laravel 5 - env() always returns null

I try to find out why my env() helper always returns null. This causes trouble especially in app.php file, where are env() helpers widely used by default. Perhaps any mysterious server setting? My env…
Fusion
  • 5,046
  • 5
  • 42
  • 51
59
votes
6 answers

What is difference between use env('APP_ENV'), config('app.env') or App::environment() to get app environment?

What is difference between use env('APP_ENV'), config('app.env') or App::environment() to get app environment? I know that the env('APP_ENV') will to $_ENV, config('app.env') reads the configuration and App::environment() is an abstraction of all.…
Miguel Borges
  • 7,549
  • 8
  • 39
  • 57
41
votes
10 answers

How to specify a different .env file for phpunit in Laravel 5?

I have a .env file containing my database connection details, as is normal for Laravel 5. I want to override these for testing, which I can do in phpunit.xml. However, doing this seems to go against the philosophy of .env which is not to commit…
Gnuffo1
  • 3,478
  • 11
  • 39
  • 53
23
votes
13 answers

Laravel 5.8 , artisan commands error : Failed to parse dotenv file due to an invalid name

This problem only happens with Laravel 5.8 on my shared hosting. It is working fine in my shared hosting with Laravel 5.7. It is working fine in my local environment with Laravel 5.8. the problem is: every time I run php artisan commands (on my…
13
votes
4 answers

Dotenv must be an instance of Dotenv\Loader

I installed phpdotenv from vlucas using composer on a codeigniter project. I have added the hook as well which I am bit confused if needed for v3.3 $hook['pre_system'] = function() { $dotenv = new Dotenv\Dotenv(APPPATH); …
mrsparrow
  • 371
  • 1
  • 2
  • 8
13
votes
3 answers

dotenv requires .env file on production

I'm using dotenv for PHP to manage the environment settings (not lavarel but I tagged it because lavarel also uses dotenv) I have excluded the .env from the code base and I have added the .env.example for all other collaborators On the github page…
10
votes
3 answers

Laravel PHPUnit loading .env.testing file

I have some problems with getting Laravel to load the proper .env file for my testcases. I'm using PHPUnit with the following var set in phpunit.xml:
bsgrd
  • 633
  • 1
  • 9
  • 26
10
votes
1 answer

Use multiple env files

I'm wondering if there's a way in Laravel to specify a set of env files to load. My exact problem is I want to add something like a suffix to all my .js and .css resources. Ideally I'd have a suffix like the release date because it would be ok for…
apokryfos
  • 38,771
  • 9
  • 70
  • 114
10
votes
3 answers

Why use dotenv library instead of parsing ini file?

Within PHP, *.ini files can be read by using parse_ini_file(). However, various frameworks (Laravel included) opt to, instead, bring in a separate library to parse an environment file. What is the reasoning behind using this "dotenv" solution…
Lijiebin
  • 113
  • 7
9
votes
13 answers

Fatal error: Class 'Dotenv\Dotenv' not found in

Hello guys I am so confused I dont know what I am doing wrong this told me Fatal error: Class 'Dotenv\Dotenv' not found in But I dont understand why.. $dotenv = new \Dotenv\Dotenv(dirname(dirname(dirname(dirname(__DIR__))))); $dotenv->load(); My…
Marco Perez
  • 160
  • 1
  • 1
  • 6
7
votes
1 answer

Laravel Environment Variables(without default value passed in method) not working inside Artisan Command file

I am using Laravel 6.x for client's project wherein I have built an API in the Artisan Command for syncing data. Now client wants the configuration to be discreet, out of main source code and without any fallback values as possible. That means I…
Vicky Dev
  • 1,893
  • 2
  • 27
  • 62
6
votes
1 answer

dotenv and Elastic Beanstalk - Environment file .env not found or not readable

I'm trying to upload a Lumen project in Amazon Elastic Beanstalk. .env is in .gitignore. This is OK, because I have several environement ( dev, qa, prod), so I need to configure have separate env variable for each environement I get this error…
Juliatzin
  • 18,455
  • 40
  • 166
  • 325
5
votes
1 answer

Return datatype from .env in Laravel

I want to have dynamic seeders based on my environment. (eg in testing I want so only seed 100 rows, whereas local it would be 10'000). I've created seeder.php in the config, which is calling values from the .env file. When I use the config in my…
n8udd
  • 657
  • 1
  • 9
  • 30
5
votes
1 answer

Laravel and environment variables in command line production without .env file

When I upgraded to Laravel 5 I started using the env system where I set all my configurations inside this file at the root. .env DB_HOST=x.x.x.x.x DB_USERNAME ... This file is not part of my repo and when I deploy I set the same variables onto my…
user391986
  • 29,536
  • 39
  • 126
  • 205
1
2 3 4 5 6