Skip to content

Commit db35c42

Browse files
committed
feature #4591 Instructions for setting SYMFONY_ENV on Heroku (dzuelke)
This PR was merged into the 2.3 branch. Discussion ---------- Instructions for setting SYMFONY_ENV on Heroku Much smoother sailing with that step included :) On a related note, I was going to add general advice on using `SYMFONY_ENV`, as it is currently very under-documented (just one aside mention at http://symfony.com/doc/current/cookbook/deployment/tools.html#c-update-your-vendors), but I wasn't sure where to do this. Maybe in `cookbook/configuration/environments.rst` and a few other places? Commits ------- 576bbfb remove first person as per feedback 579fdd6 capitalize section title as per feedback 5f987ff instructions for setting SYMFONY_ENV on Heroku for smooth deploys
2 parents 727c92a + 576bbfb commit db35c42

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

cookbook/deployment/heroku.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ Deploying your Application on Heroku
7171

7272
To deploy your application to Heroku, you must first create a ``Procfile``,
7373
which tells Heroku what command to use to launch the web server with the
74-
correct settings. After you've done that, you can simply ``git push`` and
75-
you're done!
74+
correct document root. After that, you will ensure that your Symfony application
75+
runs the ``prod`` environment, and then you'll be ready to ``git push`` to
76+
Heroku for your first deploy!
7677

7778
Creating a Procfile
7879
~~~~~~~~~~~~~~~~~~~
@@ -110,6 +111,27 @@ create the ``Procfile`` file and to add it to the repository:
110111
[master 35075db] Procfile for Apache and PHP
111112
1 file changed, 1 insertion(+)
112113
114+
Setting the ``prod`` Environment
115+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
116+
117+
During a deploy, Heroku runs ``composer install --no-dev`` to install all of the
118+
dependencies your application requires. However, typical `post-install-commands`_
119+
in ``composer.json``, e.g. to install assets or clear (or pre-warm) caches, run
120+
using Symfony's ``dev`` environment by default.
121+
122+
This is clearly not what you want - the app runs in "production" (even if you
123+
use it just for an experiment, or as a staging environment), and so any build
124+
steps should use the same ``prod`` environment as well.
125+
126+
Thankfully, the solution to this problem is very simple: Symfony will pick up an
127+
environment variable named ``SYMFONY_ENV`` and use that environment if nothing
128+
else is explicitly set. As Heroku exposes all `config vars`_ as environment
129+
variables, you can issue a single command to prepare your app for a deployment:
130+
131+
.. code-block:: bash
132+
133+
$ heroku config:set SYMFONY_ENV=prod
134+
113135
Pushing to Heroku
114136
~~~~~~~~~~~~~~~~~
115137

@@ -193,3 +215,5 @@ You should be seeing your Symfony application in your browser.
193215
.. _`ephemeral file system`: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
194216
.. _`Logplex`: https://devcenter.heroku.com/articles/logplex
195217
.. _`verified that the RSA key fingerprint is correct`: https://devcenter.heroku.com/articles/git-repository-ssh-fingerprints
218+
.. _`post-install-commands`: https://getcomposer.org/doc/articles/scripts.md
219+
.. _`config vars`: https://devcenter.heroku.com/articles/config-vars

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy