Skip to content

Commit c5e409b

Browse files
committed
feature #4526 Deploy Symfony application on Platform.sh. (GuGuss)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #4526). Discussion ---------- Deploy Symfony application on Platform.sh. Commits ------- 105088a Update map.rst.inc 257e9a8 Coding standard for PHP block. 18ca974 Fix coding standards #2 29988aa Use alphabetical order. 75a1c56 Fix duplicated references. 8fb400e Add some references. a8b6df8 Reference available services 62f76bf Better match Symfony documentation standard. b70f413 Github => GitHub c2a5675 Fix typo and add Github link. b4383b5 Deploy Symfony application on Platform.sh.
2 parents 9b4d747 + 105088a commit c5e409b

File tree

3 files changed

+192
-0
lines changed

3 files changed

+192
-0
lines changed

cookbook/deployment/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Deployment
77
tools
88
azure-website
99
heroku
10+
platformsh

cookbook/deployment/platformsh.rst

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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, it is assumed 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. Once your project is ready, give it a name
21+
and choose: **Import an existing site**.
22+
23+
Prepare Your Application
24+
~~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
To deploy your Symfony application on Platform.sh, you simply need to add a
27+
``.platform.app.yaml`` at the root of your Git repository which will tell
28+
Platform.sh how to deploy your application (read more about
29+
`Platform.sh configuration files`_).
30+
31+
.. code-block:: yaml
32+
33+
# .platform.app.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: myphpproject
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+
For best practices, you should also add a ``.platform`` folder at the root of
75+
your Git repository which contains the following files:
76+
77+
.. code-block:: yaml
78+
79+
# .platform/routes.yaml
80+
"http://{default}/":
81+
type: upstream
82+
upstream: "php:php"
83+
84+
.. code-block:: yaml
85+
86+
# .platform/services.yaml
87+
mysql:
88+
type: mysql
89+
disk: 2048
90+
91+
An example of these configurations can be found on `GitHub`_. The list of
92+
`available services <configure-services>`_ can be found on the Platform.sh documentation.
93+
94+
Configure Database Access
95+
~~~~~~~~~~~~~~~~~~~~~~~~~
96+
97+
Platform.sh overrides your database specific configuration via importing the
98+
following file::
99+
100+
// app/config/parameters_platform.php
101+
<?php
102+
$relationships = getenv("PLATFORM_RELATIONSHIPS");
103+
if (!$relationships) {
104+
return;
105+
}
106+
107+
$relationships = json_decode(base64_decode($relationships), true);
108+
109+
foreach ($relationships['database'] as $endpoint) {
110+
if (empty($endpoint['query']['is_master'])) {
111+
continue;
112+
}
113+
114+
$container->setParameter('database_driver', 'pdo_' . $endpoint['scheme']);
115+
$container->setParameter('database_host', $endpoint['host']);
116+
$container->setParameter('database_port', $endpoint['port']);
117+
$container->setParameter('database_name', $endpoint['path']);
118+
$container->setParameter('database_user', $endpoint['username']);
119+
$container->setParameter('database_password', $endpoint['password']);
120+
$container->setParameter('database_path', '');
121+
}
122+
123+
# Store session into /tmp.
124+
ini_set('session.save_path', '/tmp/sessions');
125+
126+
Make sure this file is listed in your *imports*:
127+
128+
.. code-block:: yaml
129+
130+
# app/config/config.yml
131+
imports:
132+
- { resource: parameters_platform.php }
133+
134+
Deploy your Application
135+
~~~~~~~~~~~~~~~~~~~~~~~
136+
137+
Now you need to add a remote to Platform.sh in your Git repository (copy the
138+
command that you see on the Platform.sh web UI):
139+
140+
.. code-block:: bash
141+
142+
$ git remote add platform [PROJECT-ID]@git.[CLUSTER].platform.sh:[PROJECT-ID].git
143+
144+
``PROJECT-ID``
145+
Unique identifier of your project. Something like ``kjh43kbobssae``
146+
``CLUSTER``
147+
Server location where your project is deplyed. It can be ``eu`` or ``us``
148+
149+
Commit the Platform.sh specific files created in the previous section:
150+
151+
.. code-block:: bash
152+
153+
$ git add .platform.app.yaml .platform/*
154+
$ git add app/config/config.yml app/config/parameters_platform.php
155+
$ git commit -m "Adding Platform.sh configuration files."
156+
157+
Push your code base to the newly added remote:
158+
159+
.. code-block:: bash
160+
161+
$ git push platform master
162+
163+
That's it! Your application is being deployed on Platform.sh and you'll soon be
164+
able to access it in your browser.
165+
166+
Every code change that you do from now on will be pushed to Git in order to
167+
redeploy your environment on Platform.sh.
168+
169+
More information about `migrating your database and files <migrate-existing-site>`_ can be found on the
170+
Platform.sh documentation.
171+
172+
Deploy a new Site
173+
-----------------
174+
175+
You can start a new `Platform.sh project`_. Choose the development plan and go
176+
through the checkout process.
177+
178+
Once your project is ready, give it a name and choose: **Create a new site**.
179+
Choose the *Symfony* stack and a starting point such as *Standard*.
180+
181+
That's it! Your Symfony application will be bootstrapped and deployed. You'll
182+
soon be able to see it in your browser.
183+
184+
.. _`Platform.sh`: https://platform.sh
185+
.. _`Platform.sh documentation`: https://docs.platform.sh/toolstacks/symfony/symfony-getting-started
186+
.. _`Platform.sh project`: https://marketplace.commerceguys.com/platform/buy-now
187+
.. _`Platform.sh configuration files`: https://docs.platform.sh/reference/configuration-files
188+
.. _`GitHub`: https://github.com/platformsh/platformsh-examples
189+
.. _`configure-services`: https://docs.platform.sh/reference/configuration-files/#configure-services
190+
.. _`migrate-existing-site`: https://docs.platform.sh/toolstacks/symfony/migrate-existing-site/

cookbook/map.rst.inc

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* :doc:`/cookbook/deployment/tools`
5555
* :doc:`/cookbook/deployment/azure-website`
5656
* :doc:`/cookbook/deployment/heroku`
57+
* :doc:`/cookbook/deployment/platformsh`
5758

5859
* :doc:`/cookbook/doctrine/index`
5960

0 commit comments

Comments
 (0)