|
1 | 1 | .. index::
|
2 |
| - single: Deployment Tools |
| 2 | + single: Deployment |
3 | 3 |
|
4 |
| -Deployment Tools |
5 |
| -================ |
| 4 | +Deploying a Symfony2 Application |
| 5 | +================================ |
6 | 6 |
|
7 |
| -This cookbook entry will teach you the what and how of Symfony2 application deployment. |
| 7 | +.. note:: |
8 | 8 |
|
| 9 | + Deploying can be a complex and varied task depending on your setup and needs. |
| 10 | + This entry doesn't try to explain everything, but rather offers the most |
| 11 | + common requirements and ideas for deployment. |
9 | 12 |
|
10 |
| -What is deployment? |
11 |
| -------------------- |
12 |
| - |
13 |
| -Deploying software changes to your website is a critical step in the lifecycle of your application. |
14 |
| -How you deploy the changes can affect how others perceive the stability and quality of your website. |
| 13 | +Symfony2 Deployment Basics |
| 14 | +-------------------------- |
15 | 15 |
|
16 | 16 | The typical steps taken while deploying a Symfony2 application include:
|
17 | 17 |
|
18 |
| -1. Uploading your modified code to the live server |
19 |
| -2. Updating your vendor dependencies via composer |
20 |
| -3. Running database migrations to update any changed data structures. |
21 |
| -4. Clearing (and perhaps more importantly, warming up) your cache |
| 18 | +#. Upload your modified code to the live server; |
| 19 | +#. Update your vendor dependencies (typically done via ``bin/vendors``, and may |
| 20 | + be done before uploading); |
| 21 | +#. Running database migrations or similar tasks to update any changed data structures; |
| 22 | +#. Clearing (and perhaps more importantly, warming up) your cache. |
22 | 23 |
|
23 | 24 | A deployment may also include other things, such as:
|
24 | 25 |
|
25 |
| -* Tagging a particular version of of your code as a release in your source control repository |
26 |
| -* Creating a temporary staging area to build your updated setup 'offline' |
27 |
| -* Running any tests available to ensure code and/or server stability |
28 |
| -* Removal of any unnecessary files from `web` to keep your production environment clean |
29 |
| -* Clearing of external cache systems (like `Memcached`_ or `Redis`_) |
30 |
| - |
| 26 | +* Tagging a particular version of of your code as a release in your source control repository; |
| 27 | +* Creating a temporary staging area to build your updated setup "offline"; |
| 28 | +* Running any tests available to ensure code and/or server stability; |
| 29 | +* Removal of any unnecessary files from ``web`` to keep your production environment clean; |
| 30 | +* Clearing of external cache systems (like `Memcached`_ or `Redis`_). |
31 | 31 |
|
32 | 32 | How to deploy a Symfony2 application
|
33 | 33 | ------------------------------------
|
34 | 34 |
|
35 | 35 | There are several ways you can deploy a Symfony2 application.
|
36 | 36 |
|
37 |
| -Let's start with a few basic examples of where developers typically begin with their |
38 |
| -deployment strategies, and build on things from there. |
| 37 | +Let's start with a few basic deployment strategies and build up from there. |
| 38 | + |
| 39 | +Basic File Transfer |
| 40 | +~~~~~~~~~~~~~~~~~~~ |
| 41 | + |
| 42 | +The most basic way of deploying an application is copying the files manually |
| 43 | +via ftp/scp (or similar method). This has its disadvantages as you lack control |
| 44 | +over the system as the upgrade progresses. This method also requires you |
| 45 | +to take some manual steps after transferring the files (see `Common Post-Deployment Tasks`_) |
| 46 | + |
| 47 | +Using Source Control |
| 48 | +~~~~~~~~~~~~~~~~~~~~ |
| 49 | + |
| 50 | +If you're using source control (e.g. git or svn), you can simplify by having |
| 51 | +your live installation also be a copy of your repository. When you're ready |
| 52 | +to upgrade it is as simple as fetching the latest updates from your source |
| 53 | +control system. |
| 54 | + |
| 55 | +This makes updating your files *easier*, but you still need to worry about |
| 56 | +manually taking other steps (see `Common Post-Deployment Tasks`_). |
| 57 | + |
| 58 | +Using Build scripts and other Tools |
| 59 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 60 | + |
| 61 | +There are also high-quality tools to help ease the pain of deployment. There |
| 62 | +are even a few tools which have been specifically tailored to the requirements of |
| 63 | +Symfony2, and which take special care to ensure that everything before, during, |
| 64 | +and after a deployment has gone correctly. |
| 65 | + |
| 66 | +See `The Tools`_ for a list of tools that can help with deployment. |
| 67 | + |
| 68 | +Common Post-Deployment Tasks |
| 69 | +---------------------------- |
| 70 | + |
| 71 | +After deploying your actual source code, there are a number of common things |
| 72 | +you'll need to do: |
| 73 | + |
| 74 | +A) Configure your ``app/config/parameters.ini`` file |
| 75 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 76 | + |
| 77 | +This file should be customized on each system. The method you use to |
| 78 | +deploy your source code should *not* deploy this file. Instead, you should |
| 79 | +set it up manually (or via some build process) on your server(s). |
| 80 | + |
| 81 | +B) Update your vendors |
| 82 | +~~~~~~~~~~~~~~~~~~~~~~ |
39 | 83 |
|
40 |
| -* The most basic way of deploying an application is copying the files manually via ftp |
41 |
| - (or similar method). This is one of the worst methods because of the complete lack of |
42 |
| - control you have over the system as the upgrade progresses. |
| 84 | +Your vendors can be updated before transferring your source code (i.e. |
| 85 | +update the ``vendor/`` directory, then transfer that with your source |
| 86 | +code) or afterwards on the server. Either way, just update your vendors |
| 87 | +as your normally do: |
43 | 88 |
|
44 |
| -* When using a source code versioning tool (such as git or subversion), you can |
45 |
| - simplify this by instead having your live installation also be a copy of your repository, |
46 |
| - so when you're ready to upgrade it is as simple as fetching the latest updates from |
47 |
| - your source control system. This way still causes problems when you have to incorporate |
48 |
| - database migrations, however. It does improve upon the prior method, however, as only |
49 |
| - the files that were changed would need to be updated, and that means your application |
50 |
| - will be in an unstable state for far less time. |
| 89 | +.. code-block:: bash |
51 | 90 |
|
52 |
| -* There are tools to help ease the pains of deployment, and their use is becoming more widespread. |
53 |
| - Now we even have a few tools which have been specifically tailored to the requirements of |
54 |
| - Symfony2, that take special care to ensure that everything before, during, and after a deployment |
55 |
| - has gone correctly, and is able to halt (and roll back, if necessary) the process should an error |
56 |
| - occur. |
| 91 | + $ php bin/vendors install |
57 | 92 |
|
58 |
| -Deployment of an application require care. The use of staging, testing, QA, |
59 |
| -continuous integration, database migrations and capability to roll back in case of failure |
60 |
| -are all strongly advised. There are simple and more complex tools and one can make |
61 |
| -the deployment as easy (or sophisticated) as your environment requires. |
| 93 | +C) Clear your Symfony cache |
| 94 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
62 | 95 |
|
63 |
| -Don't forget that deploying your application also involves updating any dependency (via |
64 |
| -composer), migrating your database, and clearing your cache. You may even need permission |
65 |
| -management, and the ability to add, edit, or remove cron jobs. |
| 96 | +Make sure you clear (and warm-up) your Symfony cache: |
66 | 97 |
|
67 |
| -Next, we will take a look at some of the more popular options. |
| 98 | +.. code-block:: bash |
| 99 | +
|
| 100 | + $ php app/console cache:clear --env=prod --no-debug |
| 101 | +
|
| 102 | +D) Other things! |
| 103 | +~~~~~~~~~~~~~~~~ |
| 104 | + |
| 105 | +There may be lots of other things that you need to do, depending on your |
| 106 | +setup: |
| 107 | + |
| 108 | +* Running any database migrations |
| 109 | +* Clearing your APC cache |
| 110 | +* Dumping your Assetic assets (taken care of already in ``cache:clear``) |
| 111 | +* Running ``assets:install`` (taken care of already in ``bin/vendors``) |
| 112 | +* Add/edit CRON jobs |
| 113 | +* Pushing assets to a CDN |
| 114 | +* ... |
| 115 | + |
| 116 | +Application Lifecycle: Continuous Integration, QA, etc |
| 117 | +------------------------------------------------------ |
| 118 | + |
| 119 | +While this entry covers the technical details of deploying, the full lifecycle |
| 120 | +of taking code from development up to production may have a lot more steps |
| 121 | +(think deploying to staging, QA, running tests, etc). |
| 122 | + |
| 123 | +The use of staging, testing, QA, continuous integration, database migrations |
| 124 | +and the capability to roll back in case of failure are all strongly advised. There |
| 125 | +are simple and more complex tools and one can make the deployment as easy |
| 126 | +(or sophisticated) as your environment requires. |
| 127 | + |
| 128 | +Don't forget that deploying your application also involves updating any dependency |
| 129 | +(typically via ``bin/vendors``), migrating your database, clearing your cache and |
| 130 | +other potential things like pushing assets to a CDN (see `Common Post-Deployment Tasks`_). |
68 | 131 |
|
69 | 132 | The Tools
|
70 | 133 | ---------
|
71 | 134 |
|
72 | 135 | `Capifony`_:
|
73 | 136 |
|
74 |
| - This tool provides a specialized set of tools on top of Capistrano, tailored specifically to symfony and Symfony2 projects. |
75 |
| - |
76 |
| -`Magallanes`_: |
77 |
| - |
78 |
| - This Capistrano-like deployment tool is built in PHP, and may be easier for PHP developers to extend for their needs. |
| 137 | + This tool provides a specialized set of tools on top of Capistrano, tailored |
| 138 | + specifically to symfony and Symfony2 projects. |
79 | 139 |
|
80 | 140 | `sf2debpkg`_:
|
81 | 141 |
|
82 | 142 | This tool helps you build a native Debian package for your Symfony2 project.
|
83 | 143 |
|
| 144 | +`Magallanes`_: |
| 145 | + |
| 146 | + This Capistrano-like deployment tool is built in PHP, and may be easier |
| 147 | + for PHP developers to extend for their needs. |
| 148 | + |
84 | 149 | Bundles:
|
85 | 150 |
|
86 |
| - There are many `bundles that add deployment features`_ directly into your Symfony2 console. |
| 151 | + There are many `bundles that add deployment features`_ directly into your |
| 152 | + Symfony2 console. |
87 | 153 |
|
88 | 154 | Basic scripting:
|
89 | 155 |
|
90 |
| - You can of course use shell, `Ant`_, or any other build tool to script the deploying of your project. |
| 156 | + You can of course use shell, `Ant`_, or any other build tool to script |
| 157 | + the deploying of your project. |
91 | 158 |
|
92 | 159 | Platform as a Service Providers:
|
93 | 160 |
|
94 |
| - PaaS is a relatively new way to deploy your application. Typically a PaaS will use a single configuration file |
95 |
| - in your project's root directory to detrmine how to build an environment on the fly that supports your software. |
| 161 | + PaaS is a relatively new way to deploy your application. Typically a PaaS |
| 162 | + will use a single configuration file in your project's root directory to |
| 163 | + determine how to build an environment on the fly that supports your software. |
96 | 164 | One provider with confirmed Symfony2 support is `PagodaBox`_.
|
97 | 165 |
|
98 |
| - |
99 | 166 | .. tip::
|
100 | 167 |
|
101 |
| - Looking for more? Talk to the community on the `Symfony IRC channel`_ #symfony (on freenode) for more information. |
| 168 | + Looking for more? Talk to the community on the `Symfony IRC channel`_ #symfony |
| 169 | + (on freenode) for more information. |
102 | 170 |
|
103 | 171 | .. _`Capifony`: https://capifony.org/
|
104 | 172 | .. _`sf2debpkg`: https://github.com/liip/sf2debpkg
|
|
0 commit comments