Deploying Symfony 4 App to Heroku (PHP Fatal error

2019-07-30 17:46发布

I'm trying to deploy a symfony app to heroku but after the command "git push heroku master" i got this error

*remote: Script cache:clear returned with error code 255

remote: !! PHP Fatal error: Uncaught RuntimeException: APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file. in /tmp/build_c283120b0d4ffbcbe11960331dfe8069/bin/console:20

remote: !! Stack trace:

remote: !! #0 {main} remote: !! thrown in /tmp/build_c283120b0d4ffbcbe11960331dfe8069/bin/console on line 20 remote: !! remote: Script @auto-scripts was called via post-install-cmd remote: ! WARNING: The APP_ENV environment variable is missing remote: ! Run 'heroku config:set APP_ENV=prod' to set it.

remote: remote: ! ERROR: Dependency installation failed!

remote: ! remote: ! The 'composer install' process failed with an error. The cause remote: ! may be the download or installation of packages, or a pre- or remote: ! post-install hook (e.g. a 'post-install-cmd' item in 'scripts') remote: ! in your 'composer.json'.

remote: ! remote: ! Typical error cases are out-of-date or missing parts of code, remote: ! timeouts when making external connections, or memory limits.

remote: ! remote: ! Check the above error output closely to determine the cause of remote: ! the problem, ensure the code you're pushing is functioning remote: ! properly, and that all local changes are committed correctly.

remote: ! remote: ! For more information on builds for PHP on Heroku, refer to remote: !
https://devcenter.heroku.com/articles/php-support

remote: ! remote: ! REMINDER: the following warnings were emitted during the build; remote: ! check the details above, as they may be related to this error: remote: ! - The APP_ENV environment variable is missing

remote: remote: ! Push rejected, failed to compile PHP app.

remote: remote: ! Push failed remote: Verifying deploy...*

I changed the line APP_ENV=dev to APP_ENV=prod on .env file but nothing changed... any ideas? How do I add "symfony/dotenv" as a Composer dependency?

1条回答
走好不送
2楼-- · 2019-07-30 18:01

The error message is pretty clear about this:

You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.

It ain't enough to just create a .env file! You must also add symfony/dotenv as a composer dependency for symfony to actually use the environment variables defined in the .env file.

Run the following command and re-deploy your application to fix your issue:

composer require symfony/dotenv

Another way to fix the issue is to configure Heroku to provide the APP_ENV environment variable when running your application.

heroku config:set APP_ENV=prod
查看更多
登录 后发表回答