-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Deploy Symfony application on Platform.sh. #4526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
0ada668
feb2d3b
e74458a
5fd2254
a3716d9
5e20a5e
498517d
1e715d9
6693e78
4e2e14a
c160c87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,5 +5,6 @@ Deployment | |
:maxdepth: 2 | ||
|
||
tools | ||
platformsh | ||
azure-website | ||
heroku |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
.. index:: | ||
single: Deployment; Deploying to Platform.sh | ||
|
||
Deploying to Platform.sh | ||
======================== | ||
|
||
This step by step cookbook describes how to deploy a Symfony web application to | ||
`Platform.sh`_ . You can read more about using Symfony with Platform.sh on the | ||
official `Platform.sh documentation`_. | ||
|
||
Deploy an existing site | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deploy an Existing Site (according to our headline capitalisation rules) |
||
----------------------- | ||
|
||
In this guide, we assume your codebase is already versioned with Git. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "it is assumed" because we avoid the first person perspective |
||
|
||
Get a project on Platform.sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Project |
||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
You need to subscribe to a `Platform.sh project`_. Choose the development plan | ||
and go through the checkout process. | ||
|
||
Once your project is ready, give it a name and choose: **Import an existing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that this needs to be a new paragraph. |
||
site**. | ||
|
||
Prepare your Application | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your |
||
~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
To deploy your Symfony application on Platform.sh, you simply need to add a | ||
``.platform.app.yaml`` at the root of your Git repository which will tell | ||
Platform.sh how to deploy your application (read more about `Platform.sh | ||
configuration files`_). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're used to put roles on the same line. So could you add a linebreak before ``Platform.sh configuration files |
||
|
||
.. code-block:: yaml | ||
|
||
# This file describes an application. You can have multiple applications | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could add the filename in a YAML comment like we use to do it in the documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. standards state that there should be an empty line between a file comment and a normal comment. |
||
# in the same project. | ||
|
||
# The name of this app. Must be unique within a project. | ||
name: php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this has to be unique, wouldn't |
||
|
||
# The toolstack used to build the application. | ||
toolstack: "php:symfony" | ||
|
||
# The relationships of the application with services or other applications. | ||
# The left-hand side is the name of the relationship as it will be exposed | ||
# to the application in the PLATFORM_RELATIONSHIPS variable. The right-hand | ||
# side is in the form `<service name>:<endpoint name>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's a good idea to link to a reference of existing services. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done on the services specific part. |
||
relationships: | ||
database: "mysql:mysql" | ||
|
||
# The configuration of app when it is exposed to the web. | ||
web: | ||
# The public directory of the app, relative to its root. | ||
document_root: "/web" | ||
# The front-controller script to send non-static requests to. | ||
passthru: "/app.php" | ||
|
||
# The size of the persistent disk of the application (in MB). | ||
disk: 2048 | ||
|
||
# The mounts that will be performed when the package is deployed. | ||
mounts: | ||
"/app/cache": "shared:files/cache" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't there a way to have cache in a non-shared writable location instead ? Having a shared cache folder can create issues, especially when it gets shared between the active version and the version being deployed (before the end of the deployment process) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, the "shared" means that the volume is accessible by all the applications that are deployed inside an environment. It's not shared between 2 deployments of the same environment (ie: the active and the one being deployed). For example, if you clear the cache as part of the build process, it'll be fresh for the new deployment. It's a concept specific to Platform.sh since we support multiple application inside the same repository (Symfony, Drupal, NodeJS...). |
||
"/app/logs": "shared:files/logs" | ||
|
||
# The hooks that will be performed when the package is deployed. | ||
hooks: | ||
build: | | ||
rm web/app_dev.php | ||
app/console --env=prod assetic:dump --no-debug | ||
deploy: | | ||
app/console --env=prod cache:clear | ||
|
||
# The configuration of scheduled execution. | ||
# see http://symfony.com/doc/current/components/console/introduction.html | ||
#crons: | ||
# symfony: | ||
# spec: "*/20 * * * *" | ||
# cmd: "php cron.php example:test" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section should be removed. |
||
|
||
For best practices, you should also add a ``.platform`` folder at the root of | ||
your Git repository which contains the following files: | ||
|
||
.. code-block:: yaml | ||
|
||
# .platform/routes.yaml | ||
"http://{default}/": | ||
type: upstream | ||
upstream: "php:php" | ||
|
||
.. code-block:: yaml | ||
|
||
# .platform/services.yaml | ||
mysql: | ||
type: mysql | ||
disk: 2048 | ||
|
||
Configure database access | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Configure Database Access |
||
~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Platform.sh overrides your database specific configuration via importing the | ||
following file: | ||
|
||
.. code-block:: yaml | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's PHP code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, is this an automatically generated file? Otherwise we should change it to match the Symfony coding style. |
||
|
||
# app/config/parameters_platform.php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for PHP files, please use a PHP comment: // app/config/parameters_platform.php There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stof sorry for being ultra-pedantic, but as you always are so precise, I just wanted to say that shell-style comments are one of the three valid styles for PHP comments. Having said this, you are absolutely right because in the rest of the Symfony documentation we always use the "one-line c++ style comment" that starts with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes thet are, but our coding standards are explicitly forbidding them |
||
<?php | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we usually don't add this tag in all other examples in the docs. Is there a very good reason to do here? |
||
$relationships = getenv("PLATFORM_RELATIONSHIPS"); | ||
if (!$relationships) { | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong indentation (throughout the whole example), it should be 4 spaces |
||
} | ||
|
||
$relationships = json_decode(base64_decode($relationships), TRUE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
foreach ($relationships['database'] as $endpoint) { | ||
if (empty($endpoint['query']['is_master'])) { | ||
continue; | ||
} | ||
|
||
$container->setParameter('database_driver', 'pdo_' . $endpoint['scheme']); | ||
$container->setParameter('database_host', $endpoint['host']); | ||
$container->setParameter('database_port', $endpoint['port']); | ||
$container->setParameter('database_name', $endpoint['path']); | ||
$container->setParameter('database_user', $endpoint['username']); | ||
$container->setParameter('database_password', $endpoint['password']); | ||
$container->setParameter('database_path', ''); | ||
} | ||
|
||
# Hack. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the "#Hack" comment or find a solution :) |
||
ini_set('session.save_path', '/tmp/sessions'); | ||
|
||
Make sure this file is listed in your *imports*: | ||
|
||
.. code-block:: yaml | ||
|
||
# app/config/config.yml | ||
imports: | ||
- { resource: parameters_platform.php } | ||
|
||
Deploy your Application | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Now you need to add a remote to Platform.sh in your Git repository (copy the | ||
command that you see on the Platform.sh web UI): | ||
|
||
.. code-block:: bash | ||
|
||
$ git remote add platform kjh43kbobssae@git.eu.platform.sh:kjh43kbobssae.git | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would prefer something like
|
||
|
||
Commit the Platform.sh specific files created in the previous section: | ||
|
||
.. code-block:: bash | ||
|
||
$ git add .platform.app.yaml .platform/* | ||
$ git add app/config/config.yml app/config/parameters_platform.php | ||
$ git commit -m "Adding Platform.sh configuration files." | ||
|
||
Push your code base to the newly added remote: | ||
|
||
.. code-block:: bash | ||
|
||
$ git push -u platform master | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not show the |
||
|
||
Counting objects: 27, done. | ||
Delta compression using up to 4 threads. | ||
Compressing objects: 100% (11/11), done. | ||
Writing objects: 100% (16/16), 2.47 KiB | 0 bytes/s, done. | ||
Total 16 (delta 7), reused 12 (delta 5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this Git output could be hidden. It is not relevant here |
||
|
||
Processing activity environment.push | ||
Found 213 new commits. | ||
|
||
Building application 'php' with toolstack 'php:symfony' (tree: 2248cf8) | ||
Found a `composer.json`, installing dependencies. | ||
... | ||
|
||
That's it! Your application is being deployed on Platform.sh and you'll soon be | ||
able to access it in your browser. | ||
|
||
Deploy a new site | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Site |
||
----------------- | ||
|
||
You can start a new `Platform.sh project`_. Choose the development plan and go | ||
through the checkout process. | ||
|
||
Once your project is ready, give it a name and choose: **Create a new site**. | ||
Choose the *Symfony* stack and a starting point such as *Standard*. | ||
|
||
That's it! Your Symfony application will be bootstaped and deployed. You'll soon | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bootstaped -> bootstrapped |
||
be able to see it in your browser. | ||
|
||
.. _`Platform.sh`: https://platform.sh | ||
.. _`Platform.sh documentation`: https://docs.platform.sh/toolstacks/symfony/symfony-getting-started/ | ||
.. _`Platform.sh project`: https://marketplace.commerceguys.com/platform/buy-now | ||
.. _`Platform.sh configuration files`: https://docs.platform.sh/reference/configuration-files/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to keep the different PaaS providers ordered alphabetically (we need a to sort them in a way which does not advantage one of the IMO, and the alphabetical one is probably the easiest to justify)