|
| 1 | +.. index:: |
| 2 | + single: Deployment; Deploying to Platform.sh |
| 3 | + |
| 4 | +Deploying to Platform.sh |
| 5 | +======================== |
| 6 | + |
| 7 | +This step by step cookbook describes how to deploy a Symfony web application to |
| 8 | +`Platform.sh`_ . You can read more about using Symfony with Platform.sh on the |
| 9 | +official `Platform.sh documentation`_. |
| 10 | + |
| 11 | +Deploy an existing site |
| 12 | +----------------------- |
| 13 | + |
| 14 | +In this guide, we assume your codebase is already versioned with Git. |
| 15 | + |
| 16 | +Get a project on Platform.sh |
| 17 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 18 | + |
| 19 | +You need to subscribe to a `Platform.sh project`_. Choose the development plan |
| 20 | +and go through the checkout process. |
| 21 | + |
| 22 | +Once your project is ready, give it a name and choose: **Import an existing |
| 23 | +site**. |
| 24 | + |
| 25 | +Prepare your Application |
| 26 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | + |
| 28 | +To deploy your Symfony application on Platform.sh, you simply need to add a |
| 29 | +``.platform.app.yaml`` at the root of your Git repository which will tell |
| 30 | +Platform.sh how to deploy your application (read more about `Platform.sh |
| 31 | +configuration files`_). |
| 32 | + |
| 33 | +.. code-block:: yaml |
| 34 | +
|
| 35 | + # This file describes an application. You can have multiple applications |
| 36 | + # in the same project. |
| 37 | +
|
| 38 | + # The name of this app. Must be unique within a project. |
| 39 | + name: php |
| 40 | +
|
| 41 | + # The toolstack used to build the application. |
| 42 | + toolstack: "php:symfony" |
| 43 | +
|
| 44 | + # The relationships of the application with services or other applications. |
| 45 | + # The left-hand side is the name of the relationship as it will be exposed |
| 46 | + # to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand |
| 47 | + # side is in the form `<service name>:<endpoint name>`. |
| 48 | + relationships: |
| 49 | + database: "mysql:mysql" |
| 50 | +
|
| 51 | + # The configuration of app when it is exposed to the web. |
| 52 | + web: |
| 53 | + # The public directory of the app, relative to its root. |
| 54 | + document_root: "/web" |
| 55 | + # The front-controller script to send non-static requests to. |
| 56 | + passthru: "/app.php" |
| 57 | +
|
| 58 | + # The size of the persistent disk of the application (in MB). |
| 59 | + disk: 2048 |
| 60 | +
|
| 61 | + # The mounts that will be performed when the package is deployed. |
| 62 | + mounts: |
| 63 | + "/app/cache": "shared:files/cache" |
| 64 | + "/app/logs": "shared:files/logs" |
| 65 | +
|
| 66 | + # The hooks that will be performed when the package is deployed. |
| 67 | + hooks: |
| 68 | + build: | |
| 69 | + rm web/app_dev.php |
| 70 | + app/console --env=prod assetic:dump --no-debug |
| 71 | + deploy: | |
| 72 | + app/console --env=prod cache:clear |
| 73 | +
|
| 74 | + # The configuration of scheduled execution. |
| 75 | + # see http://symfony.com/doc/current/components/console/introduction.html |
| 76 | + #crons: |
| 77 | + # symfony: |
| 78 | + # spec: "*/20 * * * *" |
| 79 | + # cmd: "php cron.php example:test" |
| 80 | +
|
| 81 | +For best practices, you should also add a ``.platform`` folder at the root of |
| 82 | +your Git repository which contains the following files: |
| 83 | + |
| 84 | +.. code-block:: yaml |
| 85 | +
|
| 86 | + # .platform/routes.yaml |
| 87 | + "http://{default}/": |
| 88 | + type: upstream |
| 89 | + upstream: "php:php" |
| 90 | +
|
| 91 | +.. code-block:: yaml |
| 92 | +
|
| 93 | + # .platform/services.yaml |
| 94 | + mysql: |
| 95 | + type: mysql |
| 96 | + disk: 2048 |
| 97 | +
|
| 98 | +Configure database access |
| 99 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 100 | + |
| 101 | +Platform.sh overrides your database specific configuration via importing the |
| 102 | +following file: |
| 103 | + |
| 104 | +.. code-block:: yaml |
| 105 | + |
| 106 | + # app/config/parameters_platform.php |
| 107 | + <?php |
| 108 | + $relationships = getenv("PLATFORM_RELATIONSHIPS"); |
| 109 | + if (!$relationships) { |
| 110 | + return; |
| 111 | + } |
| 112 | +
|
| 113 | + $relationships = json_decode(base64_decode($relationships), TRUE); |
| 114 | +
|
| 115 | + foreach ($relationships['database'] as $endpoint) { |
| 116 | + if (empty($endpoint['query']['is_master'])) { |
| 117 | + continue; |
| 118 | + } |
| 119 | +
|
| 120 | + $container->setParameter('database_driver', 'pdo_' . $endpoint['scheme']); |
| 121 | + $container->setParameter('database_host', $endpoint['host']); |
| 122 | + $container->setParameter('database_port', $endpoint['port']); |
| 123 | + $container->setParameter('database_name', $endpoint['path']); |
| 124 | + $container->setParameter('database_user', $endpoint['username']); |
| 125 | + $container->setParameter('database_password', $endpoint['password']); |
| 126 | + $container->setParameter('database_path', ''); |
| 127 | + } |
| 128 | +
|
| 129 | + # Hack. |
| 130 | + ini_set('session.save_path', '/tmp/sessions'); |
| 131 | +
|
| 132 | +Make sure this file is listed in your *imports*: |
| 133 | + |
| 134 | +.. code-block:: yaml |
| 135 | +
|
| 136 | + # app/config/config.yml |
| 137 | + imports: |
| 138 | + - { resource: parameters_platform.php } |
| 139 | +
|
| 140 | +Deploy your Application |
| 141 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 142 | + |
| 143 | +Now you need to add a remote to Platform.sh in your Git repository (copy the |
| 144 | +command that you see on the Platform.sh web UI): |
| 145 | + |
| 146 | +.. code-block:: bash |
| 147 | +
|
| 148 | + $ git remote add platform kjh43kbobssae@git.eu.platform.sh:kjh43kbobssae.git |
| 149 | +
|
| 150 | +Commit the Platform.sh specific files created in the previous section: |
| 151 | + |
| 152 | +.. code-block:: bash |
| 153 | +
|
| 154 | + $ git add .platform.app.yaml .platform/* |
| 155 | + $ git add app/config/config.yml app/config/parameters_platform.php |
| 156 | + $ git commit -m "Adding Platform.sh configuration files." |
| 157 | +
|
| 158 | +Push your code base to the newly added remote: |
| 159 | + |
| 160 | +.. code-block:: bash |
| 161 | +
|
| 162 | + $ git push -u platform master |
| 163 | +
|
| 164 | + Counting objects: 27, done. |
| 165 | + Delta compression using up to 4 threads. |
| 166 | + Compressing objects: 100% (11/11), done. |
| 167 | + Writing objects: 100% (16/16), 2.47 KiB | 0 bytes/s, done. |
| 168 | + Total 16 (delta 7), reused 12 (delta 5) |
| 169 | +
|
| 170 | + Processing activity environment.push |
| 171 | + Found 213 new commits. |
| 172 | +
|
| 173 | + Building application 'php' with toolstack 'php:symfony' (tree: 2248cf8) |
| 174 | + Found a `composer.json`, installing dependencies. |
| 175 | + ... |
| 176 | +
|
| 177 | +That's it! Your application is being deployed on Platform.sh and you'll soon be |
| 178 | +able to access it in your browser. |
| 179 | + |
| 180 | +Deploy a new site |
| 181 | +----------------- |
| 182 | + |
| 183 | +You can start a new `Platform.sh project`_. Choose the development plan and go |
| 184 | +through the checkout process. |
| 185 | + |
| 186 | +Once your project is ready, give it a name and choose: **Create a new site**. |
| 187 | +Choose the *Symfony* stack and a starting point such as *Standard*. |
| 188 | + |
| 189 | +That's it! Your Symfony application will be bootstaped and deployed. You'll soon |
| 190 | +be able to see it in your browser. |
| 191 | + |
| 192 | +.. _`Platform.sh`: https://platform.sh |
| 193 | +.. _`Platform.sh documentation`: https://docs.platform.sh/toolstacks/symfony/symfony-getting-started/ |
| 194 | +.. _`Platform.sh project`: https://marketplace.commerceguys.com/platform/buy-now |
| 195 | +.. _`Platform.sh configuration files`: https://docs.platform.sh/reference/configuration-files/ |
0 commit comments