Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to nest variables #98

Closed
CMDann opened this issue Jun 25, 2015 · 9 comments
Closed

Unable to nest variables #98

CMDann opened this issue Jun 25, 2015 · 9 comments

Comments

@CMDann
Copy link

CMDann commented Jun 25, 2015

We are trying to set up our CI for a laravel project, we use drone as our CI tool. We are running into an issue with the .env file where when we try to add the build number for the database we are using, it does not interpolate the string with the build number.

APP_ENV=test
APP_DEBUG=true
APP_KEY=SomeRandomString

DB_HOST=server
DB_DATABASE="BUILD_${DRONE_BUILD_NUMBER}"
DB_USERNAME=user
DB_PASSWORD=password

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null

The issue is here: DB_DATABASE="BUILD_${DRONE_BUILD_NUMBER}". We are running our laravel 5 app inside docker on a drone environment, anybody run into this before?

@gmcgibbon
Copy link

This has been fixed. We changed DB_DATABASE="BUILD_${DRONE_BUILD_NUMBER}" to DB_DATABASE="BUILD_{$DRONE_BUILD_NUMBER}".

Turns out ${...} is used for phpdotenv variables while {$...} is used for environment variables. You might want to clarify this in the documentation.

@vlucas
Copy link
Owner

vlucas commented Jun 25, 2015

phpdotenv follows the correct bash/shell syntax, which is ${...} for variable expansion and string interpolation. I just tried it in my shell:

$> export DRONE_BUILD_NUMBER=42
$> export DB_DATABASE="BUILD_${DRONE_BUILD_NUMBER}"
$> echo $DB_DATABASE                                                                                            ]
$> BUILD_42

You can also test it with:

source .env && echo $DB_DATABASE

@CMDann
Copy link
Author

CMDann commented Jun 25, 2015

👍

@VanTanev
Copy link

VanTanev commented Dec 14, 2016

phpdotenv does not properly inline env variables in laravel 5.1

$ printenv | grep MYSQL_USER
MYSQL_USER=root

$ cat .env | grep DB_USERNAME
DB_USERNAME="${MYSQL_USER}"

$ php artisan migrate --force
SQLSTATE[HY000] [1045] Access denied for user '${MYSQL_USER}'@'localhost' (using password: YES)

$ source .env && echo $DB_USERNAME
root

Switching to DB_USERNAME="{$MYSQL_USER}" inside .env fixes the issue.

I don't know if this behavior has been changed since laravel 5.1, but it would definitely be good to mention it somewhere visible. Or, since the {$VAR} version seems to always work, maybe use that example in the documentation?

@GrahamCampbell
Copy link
Collaborator

Laravel 5.1 uses an old version of this package.

@GrahamCampbell
Copy link
Collaborator

@VanTanev
Copy link

But since Laravel's docs do not specify inline semantics, and people will look to this documentation for guidance, we're left with a very confusing error. I can try and open a PR to fix the Laravel docs, but probably not the only one who would look to your docs first.

Do you think mentioning the old syntax in the main README would be useful? Something along the lines of:

"For old versions of dotenv, use {$VAR} instead of ${VAR}"

@GrahamCampbell
Copy link
Collaborator

I'd say that I'd expect people to look at the readme for the correct version?

@VanTanev
Copy link

VanTanev commented Dec 14, 2016

Unfortunately, it's not that easy to know what the correct version is when it's vendored like this. Also, 5.1 is the LTS release of Laravel, so it's expected to stick around for a good while still (2 years active dev, 3 years security fixes, starting July 19, 2016).

The docs (https://laravel.com/docs/5.1#environment-configuration) also simply link to the latest version of DotEnv (instead of to ~1.0) adding to the confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants