Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0371402

Browse filesBrowse files
committed
First draft of "Deploying to Heroku Cloud" cookbook article
1 parent 47fe03a commit 0371402
Copy full SHA for 0371402

File tree

Expand file treeCollapse file tree

2 files changed

+194
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+194
-0
lines changed

‎cookbook/deployment/heroku.rst

Copy file name to clipboard
+193Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
.. index::
2+
single: Deployment; Deploying to Heroku Cloud
3+
4+
Deploying to Heroku Cloud
5+
=========================
6+
7+
This step by step cookbook describes how to deploy a Symfony2 web application to
8+
the Heroku cloud platform. Its contents are based on `this original article`_
9+
published by Heroku.
10+
11+
Setting up
12+
----------
13+
14+
To setup a new Heroku website, first `signup with Heroku`_ or sign in
15+
with your credentials. Then, download and install the `Heroku Toolbet`_ on your
16+
local computer.
17+
18+
You can also check out the `getting Started with PHP on Heroku`_ guide to gain
19+
more familiarity with the specifics of working with PHP applications on Heroku.
20+
21+
Preparing your application
22+
~~~~~~~~~~~~~~~~~~~~~~~~~~
23+
24+
Deploying a Symfony2 application to Heroku doesn't require any change in its
25+
code, but it requires some minor tweaks in its configuration.
26+
27+
By default, the Symfony2 app will log into your application's ``app/log/``
28+
directory, which isn't ideal as Heroku uses an `ephemeral file system`_. On
29+
Heroku, the best way to handle logging is using Logplex, and the best way to
30+
send log data to Logplex is by writing to ``STDERR`` or ``STDOUT``. Luckily
31+
Symfony2 uses the excellent Monolog library for logging, and so a new log
32+
destination is just a config file change away.
33+
34+
Open ``app/config/config_prod.yml`` file, locate ``monolog/handlers/nested``
35+
section and change the value of ``path`` from
36+
``"%kernel.logs_dir%/%kernel.environment%.log"`` to ``"php://stderr"``:
37+
38+
.. code-block:: yaml
39+
40+
# app/config/config_prod.yml
41+
monolog:
42+
# ...
43+
handlers:
44+
# ...
45+
nested:
46+
# ...
47+
# path: %kernel.logs_dir%/%kernel.environment%.log
48+
path: "php://stderr"
49+
50+
Once the application is deployed, run ``heroku logs --tail`` to keep the
51+
stream of logs from Heroku open in your terminal.
52+
53+
Creating a new application on Heroku
54+
------------------------------------
55+
56+
To create a new Heroku application that you can push to, use the CLI ``create``
57+
command:
58+
59+
.. code-block:: bash
60+
61+
$ heroku create
62+
63+
Creating mighty-hamlet-1981 in organization heroku... done, stack is cedar
64+
http://mighty-hamlet-1981.herokuapp.com/ | git@heroku.com:mighty-hamlet-1981.git
65+
Git remote heroku added
66+
67+
You are now ready to deploy the application as explained in the next section.
68+
69+
Deploying your application on Heroku
70+
------------------------------------
71+
72+
To deploy your application to Heroku, you must first create a ``Procfile``,
73+
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!
76+
77+
Creating a Procfile
78+
~~~~~~~~~~~~~~~~~~~
79+
80+
By default, Heroku will launch an Apache web server together with PHP to serve
81+
applications. However, two special circumstances apply to Symfony applications:
82+
83+
1. The document root is in the ``web/`` directory and not in the root directory
84+
of the application;
85+
2. The Composer ``bin-dir``, where vendor binaries (and thus Heroku's own boot
86+
scripts) are placed, is ``bin/`` , and not the default ``vendor/bin``.
87+
88+
.. note::
89+
90+
Vendor binaries are usually installed to ``vendor/bin`` by Composer, but
91+
sometimes (e.g. when running a Symfony Standard Edition project!), the
92+
location will be different. If in doubt, you can always run
93+
``composer config bin-dir`` to figure out the right location.
94+
95+
Create a new file called ``Procfile`` (without any extension) at the root
96+
directory of the application and add just the following content:
97+
98+
.. code-block::
99+
100+
web: bin/heroku-php-apache2 web/
101+
102+
If you prefer working on the command console, execute the following commands to
103+
create the ``Procfile`` file and to add it to the repository:
104+
105+
.. code-block:: bash
106+
107+
$ echo "web: bin/heroku-php-apache2 web/" > Procfile
108+
$ git add .
109+
$ git commit -m "Procfile for Apache and PHP"
110+
[master 35075db] Procfile for Apache and PHP
111+
1 file changed, 1 insertion(+)
112+
113+
Pushing to Heroku
114+
~~~~~~~~~~~~~~~~~
115+
116+
Next up, it's finally time to deploy your application to Heroku. If you are
117+
doing this for the very first time, you may see a message such as the following:
118+
119+
.. code-block:
120+
121+
The authenticity of host 'heroku.com (50.19.85.132)' can't be established.
122+
RSA key fingerprint is 8b:48:5e:67:0e:c9:16:47:32:f2:87:0c:1f:c8:60:ad.
123+
Are you sure you want to continue connecting (yes/no)?
124+
125+
In this case, you need to confirm by typing ``yes`` and hitting ``<Enter>`` key
126+
- ideally after you've `verified that the RSA key fingerprint is correct`_.
127+
128+
Then, deploy your application executing this command:
129+
130+
.. code-block:: bash
131+
132+
$ git push heroku master
133+
134+
Initializing repository, done.
135+
Counting objects: 130, done.
136+
Delta compression using up to 4 threads.
137+
Compressing objects: 100% (107/107), done.
138+
Writing objects: 100% (130/130), 70.88 KiB | 0 bytes/s, done.
139+
Total 130 (delta 17), reused 0 (delta 0)
140+
141+
-----> PHP app detected
142+
143+
-----> Setting up runtime environment...
144+
- PHP 5.5.12
145+
- Apache 2.4.9
146+
- Nginx 1.4.6
147+
148+
-----> Installing PHP extensions:
149+
- opcache (automatic; bundled, using 'ext-opcache.ini')
150+
151+
-----> Installing dependencies...
152+
Composer version 64ac32fca9e64eb38e50abfadc6eb6f2d0470039 2014-05-24 20:57:50
153+
Loading composer repositories with package information
154+
Installing dependencies from lock file
155+
- ...
156+
157+
Generating optimized autoload files
158+
Creating the "app/config/parameters.yml" file
159+
Clearing the cache for the dev environment with debug true
160+
Installing assets using the hard copy option
161+
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
162+
Installing assets for Acme\DemoBundle into web/bundles/acmedemo
163+
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
164+
165+
-----> Building runtime environment...
166+
167+
-----> Discovering process types
168+
Procfile declares types -> web
169+
170+
-----> Compressing... done, 61.5MB
171+
172+
-----> Launching... done, v3
173+
http://mighty-hamlet-1981.herokuapp.com/ deployed to Heroku
174+
175+
To git@heroku.com:mighty-hamlet-1981.git
176+
* [new branch] master -> master
177+
178+
**And that's it!** If you now open your browser, either by manually pointing
179+
it to the URL ``heroku create`` gave you, or by using the Heroku Toolbelt, the application will respond:
180+
181+
.. code-block:: bash
182+
183+
$ heroku open
184+
Opening mighty-hamlet-1981... done
185+
186+
*Et voilà!* You should be seeing your Symfony2 application in your browser.
187+
188+
.. _`this original article`: https://devcenter.heroku.com/articles/getting-started-with-symfony2
189+
.. _`signup with Heroku`: https://signup.heroku.com/signup/dc
190+
.. _`Heroku Toolbet`: https://devcenter.heroku.com/articles/getting-started-with-php#local-workstation-setup
191+
.. _`getting Started with PHP on Heroku`: .. _`Heroku Toolbet`: https://devcenter.heroku.com/articles/getting-started-with-php
192+
.. _`ephemeral file system`: https://devcenter.heroku.com/articles/dynos#ephemeral-filesystem
193+
.. _`verified that the RSA key fingerprint is correct`: https://devcenter.heroku.com/articles/git-repository-ssh-fingerprints

‎cookbook/deployment/index.rst

Copy file name to clipboardExpand all lines: cookbook/deployment/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Deployment
66

77
tools
88
azure-website
9+
heroku

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.