Skip to content

Make app name configurable in environment file #4204

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

Merged
merged 1 commit into from
Apr 3, 2017
Merged

Make app name configurable in environment file #4204

merged 1 commit into from
Apr 3, 2017

Conversation

mdavis1982
Copy link
Contributor

This PR makes the application name configurable via an environment variable. By default, this is set to "Laravel" as per the current configuration in the app.php config file.

Why?

When developing applications with Laravel, I am often putting a version onto a staging server as well as a production server. By making the app name configurable, when I get Mailables sent to me (which, by default use the app name) I can see more easily whether the e-mail has come from the staging server or the production server.

It can also make it easier to identify which version of an application is being viewed in a browser (for example configuring the local development version with Local at the end can avoid mistakes when there are multiple tabs open with local, staging and production versions of the application.

@defaye
Copy link

defaye commented Apr 3, 2017

I do indeed find myself writing this manually into almost every project I write as well. +1

@taylorotwell taylorotwell merged commit d870a0c into laravel:master Apr 3, 2017
@danieltorscho
Copy link

danieltorscho commented Apr 23, 2017

I tought laravel's .env file is designated for a credentials and sensitive information only while the config file is used for a usual needs where you can change app's name and similiar data.

@GrahamCampbell
Copy link
Member

GrahamCampbell commented Apr 23, 2017

@danieltorscho is correct. You are meant to edit the config files in apps. However, this PR is sent more than once a month, so I suspect is was merged to stop yet more PRs.

@antonkomarev
Copy link
Contributor

@GrahamCampbell @danieltorscho This could be useful when you want to have different title for the staging\dev application for example.

@mdavis1982
Copy link
Contributor Author

@GrahamCampbell If the .env file was only for credentials and sensitive information, then there are lots of things in the standard .env file that shouldn't be there - the database connection in use, the app URL, debug level, which drivers are being used for broadcast, log, session and queue etc. The .env file should be used for things that change per environment - not just for sensitive information.

This PR isn't about not wanting to edit config files in apps - of course you're supposed to do that for the things that are consistent between every deployment / environment of your app - but there are situations where you want a different app name in different environments to make identification easier. Mailables, for example, use the app name by default, and knowing that I have a contact message from my staging area and not the production server can be quite useful.

If this PR has been sent more than once a month, that's a clear indication that there's a need for this, which I suspect is why it was merged, rather than it being just to stop more PRs of the same nature.

/cc @danieltorscho @a-komarev @m1guelpf @DojoGeekRA

@ConnorVG
Copy link

@GrahamCampbell sorry bro, I have to sit with @mdavis1982 on this one.

.env is clearly not only for credentials, it's quite obviously for generic configuration purposes that may differ based on the environment. Keywords here being "generic", "configuration" and "environment". If this file was honestly just for credentials (and the non-credential based default stuff was removed) then the file would likely be called something much different (such as .secrets or something).

As far as examples go for this being an exactly acceptable use-case for APP_NAME, I direct you at one of your (our) favourite project's .env.example file

💓

@GrahamCampbell
Copy link
Member

The file is for environment specific things, by definition. It is not exclusively for credentials, but also for things that vary per environment, such as choosing drivers.

It is not for things that are fixed per application, and is commonly abused for this.

@GrahamCampbell
Copy link
Member

(such as .secrets or something).

I actually think it would be a pretty cool idea to introduce a .secrets file to sit along side .env to avoid that file becoming really full.

@mdavis1982
Copy link
Contributor Author

@GrahamCampbell that's exactly what I said 😄 However, you did say that @danieltorscho was correct in saying that this file was designated for credentials and sensitive information only, which isn't the case.

This isn't an abuse of the .env file. The application name can have a good reason to change per environment and, therefore, is an ideal candidate to be stored in the environment file.

With regards to the .secrets file - I tend to agree. It would be neat to have credentials in there, but it would mean that some things could get separated from their other options - for example moving DB passwords away from the rest of the DB environment-specific configuration

@antonkomarev
Copy link
Contributor

antonkomarev commented Apr 23, 2017

Separating .env to .env + .secrets will bring only headache in my opinion. It will be harder to maintain it because API endpoints will be located in .env file and API keys will be in .secrets if follow the logic of extracting sensitive data to separate file.
Better leave it as is and use third party packages for such things.

@joshmanders
Copy link
Contributor

I get all points around, but it's not hard to add env('SOME_VAR', 'default') on any config you want, I just don't think that every possible config option that CAN be changed per environment for everyone's potential use case needs to be in by default.

I don't use DATABASE_* variables, as I use Heroku buildpacks, so I get a DB_HOST variable that I need to split off into their own properties for the database config to work, so does that mean I should submit a PR with that in it, and the boilerplate above config/database.php to do the splitting? Because more people use Heroku and it's buildpacks than people who want to change their app name per environment...

@ConnorVG
Copy link

@joshmanders I'm 100% willing to bet that more people change their app name than people use Heroku. That said, no you shouldn't. Don't be pedantic for the simple reason of being pedantic.

@joshmanders
Copy link
Contributor

@ConnorVG all I am saying is, if you change your app name every 3 minutes, then make the configuration changes yourself. Flooding the .env file with cruft that the majority of people don't use is annoying.

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

Successfully merging this pull request may close these issues.

8 participants