For the past week i have trying to deploy on heroku and get an handle on the system and how it works, build after build debugs after debugs, now i have reached an error that kind of baffles and i dont know which direction to take, i have setup a symfony/Bootstrap aoo deployed on Heroku, the build goes well, now that im trying to accept the app url i get a.
'
This page isn’t working interfaceapp.herokuapp.com is currently unable to handle this request. HTTP ERROR 500 ', nothing shows up on the deploy log i have to way to understand why am i getting this error.
2 Answers
After much of poking around and trying to find a solution i stumble on a rather interesting heroku cli command heroku -logs -a app_name.
i had this output :
[13-Nov-2020 10:11:15 UTC] PHP Fatal error: Uncaught Symfony\Component\Dotenv\Exception\PathException: Unable to read the "/app/.env" environment file. in /app/vendor/symfony/dotenv/Dotenv.php:565 2020-11-13T10:11:15.142981+00:00 app[web.1]: Stack trace: 2020-11-13T10:11:15.143161+00:00 app[web.1]: #0 /app/vendor/symfony/dotenv/Dotenv.php(92): Symfony\Component\Dotenv\Dotenv->doLoad() 2020-11-13T10:11:15.143350+00:00 app[web.1]: #1 /app/vendor/symfony/dotenv/Dotenv.php(114): Symfony\Component\Dotenv\Dotenv->load() 2020-11-13T10:11:15.143543+00:00 app[web.1]: #2 /app/vendor/symfony/dotenv/Dotenv.php(157): Symfony\Component\Dotenv\Dotenv->loadEnv() 2020-11-13T10:11:15.143701+00:00 app[web.1]: #3 /app/public/index.php(10): Symfony\Component\Dotenv\Dotenv->bootEnv() 2020-11-13T10:11:15.143724+00:00 app[web.1]: #4 {main} Which meant that my app couldnt read my .env file, since it is the first time im deploying a project that has a stage an prod branch, i removed the .env from both repositories (need to point out that Heroku is connected to my github repository).
My .env file from other branch contained dev env variables for the database and app_env. So what i did is i went to my heroku app dashboard, clicked on on my staging app then went to the samething and created a APP_ENV var with a value of staging. i added the postgresql add on which automaticaly created a DATABASE_URL var with a generated value attached to it.
Now for all of this to work i had to create a .env file for my staging branch on my github repo, a copy paste of the standard .env did the job, for this to be able i obviously had to remove the value attached to the APP_ENV and DATABASE_URL variables then commit and pushed it. Ran another build on Heroku now my app index page is finally showing and the error is gone :).
Some explanations based on your own answer.
The .env file is required and should be committed to your repository. However, since that file is committed to the repo, it shouldn't contain any sensitive information. See it as a way to ensure that all required environment variables are defined (even though they have invalid values such as PASSWORD=XXXXXXXXXXXX. It also can be seen as a template to create a .env.local or real environment variables. You can also include default insensitive values that are cross-environment. But the key is not to commit sensitive information in that file.
You would then use a .env.local file (that is ignored in your repository by default) to override the values in the .env file. This .env.local file would be specific to every environment where you have your application deployed. Variables defined in .env.local will win over those defined in .env.
Real environment variables will always win over those defined in .env and .env.local files.
For a Heroku deployment, I would use real environment variables as it is best suited for that and does not require you to write a file using some sort of hook upon deployment.