Skip to content

Commit 0515cb5

Browse files
committed
Created the main article about "deployment"
1 parent 683010a commit 0515cb5

File tree

3 files changed

+208
-207
lines changed

3 files changed

+208
-207
lines changed

_build/redirection_map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,5 @@
291291
/components/var_dumper/index /components/var_dumper
292292
/components/yaml/introduction /components/yaml
293293
/components/yaml/index /components/yaml
294+
/deployment/tools /deployment
294295
/install/bundles /setup/bundles

deployment.rst

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,215 @@
1+
.. index::
2+
single: Deployment; Deployment tools
3+
4+
.. _how-to-deploy-a-symfony2-application:
5+
16
Deployment
27
==========
38

9+
Deploying a Symfony application can be a complex and varied task depending on
10+
the setup and the requirements of your application. This article is not a step-
11+
by-step guide, but is a general list of the most common requirements and ideas
12+
for deployment.
13+
14+
.. _symfony2-deployment-basics:
15+
16+
Symfony Deployment Basics
17+
-------------------------
18+
19+
The typical steps taken while deploying a Symfony application include:
20+
21+
#. Upload your code to the production server;
22+
#. Install your vendor dependencies (typically done via Composer and may be done
23+
before uploading);
24+
#. Running database migrations or similar tasks to update any changed data structures;
25+
#. Clearing (and optionally, warming up) your cache.
26+
27+
A deployment may also include other tasks, such as:
28+
29+
* Tagging a particular version of your code as a release in your source control
30+
repository;
31+
* Creating a temporary staging area to build your updated setup "offline";
32+
* Running any tests available to ensure code and/or server stability;
33+
* Removal of any unnecessary files from the ``web/`` directory to keep your
34+
production environment clean;
35+
* Clearing of external cache systems (like `Memcached`_ or `Redis`_).
36+
37+
How to Deploy a Symfony Application
38+
-----------------------------------
39+
40+
There are several ways you can deploy a Symfony application. Start with a few
41+
basic deployment strategies and build up from there.
42+
43+
Basic File Transfer
44+
~~~~~~~~~~~~~~~~~~~
45+
46+
The most basic way of deploying an application is copying the files manually
47+
via FTP/SCP (or similar method). This has its disadvantages as you lack control
48+
over the system as the upgrade progresses. This method also requires you
49+
to take some manual steps after transferring the files (see `Common Post-Deployment Tasks`_)
50+
51+
Using Source Control
52+
~~~~~~~~~~~~~~~~~~~~
53+
54+
If you're using source control (e.g. Git or SVN), you can simplify by having
55+
your live installation also be a copy of your repository. When you're ready
56+
to upgrade it is as simple as fetching the latest updates from your source
57+
control system.
58+
59+
This makes updating your files *easier*, but you still need to worry about
60+
manually taking other steps (see `Common Post-Deployment Tasks`_).
61+
62+
Using Build Scripts and other Tools
63+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
64+
65+
There are also tools to help ease the pain of deployment. Some of them have been
66+
specifically tailored to the requirements of Symfony.
67+
68+
`Capistrano`_ with `Symfony plugin`_
69+
`Capistrano`_ is a remote server automation and deployment tool written in Ruby.
70+
`Symfony plugin`_ is a plugin to ease Symfony related tasks, inspired by `Capifony`_
71+
(which works only with Capistrano 2 )
72+
73+
`sf2debpkg`_
74+
Helps you build a native Debian package for your Symfony project.
75+
76+
`Magallanes`_
77+
This Capistrano-like deployment tool is built in PHP, and may be easier
78+
for PHP developers to extend for their needs.
79+
80+
`Fabric`_
81+
This Python-based library provides a basic suite of operations for executing
82+
local or remote shell commands and uploading/downloading files.
83+
84+
`Deployer`_
85+
This is another native PHP rewrite of Capistrano, with some ready recipes for
86+
Symfony.
87+
88+
Bundles
89+
There are some `bundles that add deployment features`_ directly into your
90+
Symfony console.
91+
92+
Basic scripting
93+
You can of course use shell, `Ant`_ or any other build tool to script
94+
the deploying of your project.
95+
96+
Platform as a Service Providers
97+
This guide includes detailed articles for some of the most well-known
98+
Platform as a Service (PaaS) providers:
99+
100+
* :doc:`Microsoft Azure </deployment/azure-website>`
101+
* :doc:`Heroku </deployment/heroku>`
102+
* :doc:`Platform.sh </deployment/platformsh>`
103+
104+
Common Post-Deployment Tasks
105+
----------------------------
106+
107+
After deploying your actual source code, there are a number of common things
108+
you'll need to do:
109+
110+
A) Check Requirements
111+
~~~~~~~~~~~~~~~~~~~~~
112+
113+
Check if your server meets the requirements by running:
114+
115+
.. code-block:: bash
116+
117+
$ php app/check.php
118+
119+
B) Configure your ``app/config/parameters.yml`` File
120+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121+
122+
This file should *not* be deployed, but managed through the automatic utilities
123+
provided by Symfony.
124+
125+
C) Install/Update your Vendors
126+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127+
128+
Your vendors can be updated before transferring your source code (i.e.
129+
update the ``vendor/`` directory, then transfer that with your source
130+
code) or afterwards on the server. Either way, just update your vendors
131+
as you normally do:
132+
133+
.. code-block:: bash
134+
135+
$ composer install --no-dev --optimize-autoloader
136+
137+
.. tip::
138+
139+
The ``--optimize-autoloader`` flag improves Composer's autoloader performance
140+
significantly by building a "class map". The ``--no-dev`` flag ensures that
141+
development packages are not installed in the production environment.
142+
143+
.. caution::
144+
145+
If you get a "class not found" error during this step, you may need to
146+
run ``export SYMFONY_ENV=prod`` before running this command so that
147+
the ``post-install-cmd`` scripts run in the ``prod`` environment.
148+
149+
D) Clear your Symfony Cache
150+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
151+
152+
Make sure you clear (and warm-up) your Symfony cache:
153+
154+
.. code-block:: bash
155+
156+
$ php app/console cache:clear --env=prod --no-debug
157+
158+
E) Dump your Assetic Assets
159+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
160+
161+
If you're using Assetic, you'll also want to dump your assets:
162+
163+
.. code-block:: bash
164+
165+
$ php app/console assetic:dump --env=prod --no-debug
166+
167+
F) Other Things!
168+
~~~~~~~~~~~~~~~~
169+
170+
There may be lots of other things that you need to do, depending on your
171+
setup:
172+
173+
* Running any database migrations
174+
* Clearing your APC cache
175+
* Running ``assets:install`` (already taken care of in ``composer install``)
176+
* Add/edit CRON jobs
177+
* Pushing assets to a CDN
178+
* ...
179+
180+
Application Lifecycle: Continuous Integration, QA, etc
181+
------------------------------------------------------
182+
183+
While this entry covers the technical details of deploying, the full lifecycle
184+
of taking code from development up to production may have a lot more steps
185+
(think deploying to staging, QA (Quality Assurance), running tests, etc).
186+
187+
The use of staging, testing, QA, continuous integration, database migrations
188+
and the capability to roll back in case of failure are all strongly advised. There
189+
are simple and more complex tools and one can make the deployment as easy
190+
(or sophisticated) as your environment requires.
191+
192+
Don't forget that deploying your application also involves updating any dependency
193+
(typically via Composer), migrating your database, clearing your cache and
194+
other potential things like pushing assets to a CDN (see `Common Post-Deployment Tasks`_).
195+
196+
Learn More
197+
----------
198+
4199
.. toctree::
5200
:maxdepth: 1
6201
:glob:
7202

8203
deployment/*
204+
205+
.. _`Capifony`: http://capifony.org/
206+
.. _`Capistrano`: http://capistranorb.com/
207+
.. _`sf2debpkg`: https://github.com/liip/sf2debpkg
208+
.. _`Fabric`: http://www.fabfile.org/
209+
.. _`Magallanes`: https://github.com/andres-montanez/Magallanes
210+
.. _`Ant`: http://blog.sznapka.pl/deploying-symfony2-applications-with-ant
211+
.. _`bundles that add deployment features`: http://knpbundles.com/search?q=deploy
212+
.. _`Memcached`: http://memcached.org/
213+
.. _`Redis`: http://redis.io/
214+
.. _`Symfony plugin`: https://github.com/capistrano/symfony/
215+
.. _`Deployer`: http://deployer.org/

0 commit comments

Comments
 (0)