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
2
votes
0 answers

Configure services with env vars at compile time

Until now, I've been using container parameters from an unversioned parameters.yml file to configure some bundles. The parameters where read during the container compilation to determine which services needed to be injected in a service…
nniico
  • 239
  • 2
  • 6
2
votes
2 answers

Why won't swiftmailer take the env vars?

I'm trying to configure swiftmailer to send emails from my symfony4 app, from my local environment (Wamp, win10) with gmail. The configuration works well when I add all my parameters in the config/packages/swiftmailer.yaml file but as soon as I try…
Anaïs P.
  • 21
  • 4
2
votes
1 answer

How to access settings from `.env` inside the `index.php`

I’m creating a deployment configuration for Laravel project. On my hosting public/ folder must be moved to another place. Obviously, since that, I need to change path to the autoload.php and app.php in index.php. However, I’d like to add and use a…
zhekaus
  • 3,126
  • 6
  • 23
  • 46
2
votes
1 answer

Is it a good idea to edit .env dynamically in Laravel 5?

I am building an admin panel, so I need to make some core settings (like smtp settings, etc) of my Laravel 5 app configurable to end users through front-end interface. My initial thoughts were to use database as a settings storage alongside…
Alex Lomia
  • 6,705
  • 12
  • 53
  • 87
2
votes
2 answers

Using PHP functions in .env (dotenv) file

I'm trying to use a PHP function in .env file which is rand() in my case. Here is what I'm trying to achieve in…
Sarpdoruk Tahmaz
  • 1,418
  • 3
  • 17
  • 25
1
vote
0 answers

Undefined type 'Dotenv\Dotenv\Dotenv'

Is this the way to use a package installed from composer? load(); From the screenshot, it…
Denusklo
  • 35
  • 5
1
vote
1 answer

How to change storage settings after reload custom .env file in Laravel?

I run into this issue after I loaded my custom .env.custom file in AppServiceProvider: class AppServiceProvider extends ServiceProvider { // ... public function boot() { $host = request()->getHost(); // read domain…
netdjw
  • 5,419
  • 21
  • 88
  • 162
1
vote
3 answers

Undefined type 'Dotenv\Dotenv". intelephense(1009)

I need help with this error in the screenshot below I am using PHP 7.2 and a 3rd party composer - "composer require vlucas/phpdotenv" v4.1.4. I define the base path but there is an error in the screenshot Error message Below is the _env.php code…
Emmanuel Oga
  • 69
  • 2
  • 11
1
vote
2 answers

Laravel 5.2 dynamic environment variables based on user

In my .env file I have two variables App_id: 12345 App_secret: abc123 But I'm wondering if there's a way so that if user userNo2 logs in then it would instead use App_id: 45678 App_secret: abc456 Is there a way to have if/else functionality in the…
Geoff_S
  • 4,917
  • 7
  • 43
  • 133
1
vote
2 answers

why my .env always connects with old database?

I am new to laravel. why does my laravel project keep connecting with the old database? I tried to clear cache but nothing works for me php artisan config: cache my env file is connected with the new database but shows error on terminal…
user11157722
1
vote
1 answer

How to Get Environment Value in Config File

Currently, I have an environment variable in my .env file. MY_NAME_TEST=Testing How do I pass that variable as part of a path in a config file? I'm trying to get a path similar to below: base_path('Plugins/Testing/Database/Migrations/') Notice the…
Jazzman
  • 85
  • 1
  • 8
1
vote
3 answers

How to automatically change the environment by IP

We have three development servers (dev1, dev2, stage) and one production server and some symfony projects. We would like to change the environment automatically. Currently my hack looks like this in 'public/index.php' use App\Kernel; use…
ABSimon
  • 651
  • 1
  • 6
  • 18
1
vote
1 answer

PHP Dotenv causing wordpress configuration to run twice

I have a relatively complex laravel project, within it I have a wordpress installation for a blog on the side which is installed with composer. In my wp-config.php I use an include to a file in my config directory called application.php (for…
GApple
  • 11
  • 3
1
vote
3 answers

How to edit .env files in PhpStorm?

I generated new .env file with copy .env.example .env command in PhpStorm terminal. Then created .env file then but I can't edit in PhpStorm. When I double clicked it's open external editor (Notepad++).
Kvlknctk
  • 634
  • 12
  • 27
1
vote
2 answers

PHP Fatal error: Class 'Dotenv' not found in

I've a project I try to run it but I am getting a following error: PHP Fatal error: Class 'Dotenv' not found in `/home/maras/Documents/eCodile/debtorcare/server/bootstrap/app.php on line 5` I'm struggling with this error during trying to execute a…
Marek Czyż
  • 199
  • 4
  • 16