|
| 1 | +.. index:: |
| 2 | + single: Deployment |
| 3 | + |
| 4 | +Deploying a Symfony2 Application |
| 5 | +================================ |
| 6 | + |
| 7 | +.. note:: |
| 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. |
| 12 | + |
| 13 | +Symfony2 Deployment Basics |
| 14 | +-------------------------- |
| 15 | + |
| 16 | +The typical steps taken while deploying a Symfony2 application include: |
| 17 | + |
| 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. |
| 23 | + |
| 24 | +A deployment may also include other things, such as: |
| 25 | + |
| 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 | + |
| 32 | +How to deploy a Symfony2 application |
| 33 | +------------------------------------ |
| 34 | + |
| 35 | +There are several ways you can deploy a Symfony2 application. |
| 36 | + |
| 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 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 83 | + |
| 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: |
| 88 | + |
| 89 | +.. code-block:: bash |
| 90 | +
|
| 91 | + $ php bin/vendors install |
| 92 | +
|
| 93 | +C) Clear your Symfony cache |
| 94 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 95 | + |
| 96 | +Make sure you clear (and warm-up) your Symfony cache: |
| 97 | + |
| 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`_). |
| 131 | + |
| 132 | +The Tools |
| 133 | +--------- |
| 134 | + |
| 135 | +`Capifony`_: |
| 136 | + |
| 137 | + This tool provides a specialized set of tools on top of Capistrano, tailored |
| 138 | + specifically to symfony and Symfony2 projects. |
| 139 | + |
| 140 | +`sf2debpkg`_: |
| 141 | + |
| 142 | + This tool helps you build a native Debian package for your Symfony2 project. |
| 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 | + |
| 149 | +Bundles: |
| 150 | + |
| 151 | + There are many `bundles that add deployment features`_ directly into your |
| 152 | + Symfony2 console. |
| 153 | + |
| 154 | +Basic scripting: |
| 155 | + |
| 156 | + You can of course use shell, `Ant`_, or any other build tool to script |
| 157 | + the deploying of your project. |
| 158 | + |
| 159 | +Platform as a Service Providers: |
| 160 | + |
| 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. |
| 164 | + One provider with confirmed Symfony2 support is `PagodaBox`_. |
| 165 | + |
| 166 | +.. tip:: |
| 167 | + |
| 168 | + Looking for more? Talk to the community on the `Symfony IRC channel`_ #symfony |
| 169 | + (on freenode) for more information. |
| 170 | + |
| 171 | +.. _`Capifony`: https://capifony.org/ |
| 172 | +.. _`sf2debpkg`: https://github.com/liip/sf2debpkg |
| 173 | +.. _`Ant`: http://blog.sznapka.pl/deploying-symfony2-applications-with-ant |
| 174 | +.. _`PagodaBox`: https://github.com/jmather/pagoda-symfony-sonata-distribution/blob/master/Boxfile |
| 175 | +.. _`Magallanes`: https://github.com/andres-montanez/Magallanes |
| 176 | +.. _`bundles that add deployment features`: http://knpbundles.com/search?q=deploy |
| 177 | +.. _`Symfony IRC channel`: http://webchat.freenode.net/?channels=symfony |
| 178 | +.. _`Memcached`: http://memcached.org/ |
| 179 | +.. _`Redis`: http://redis.io/ |
0 commit comments