Platform.sh Deployment
Overview
Platform.sh is a powerful hosting provider for your infrastructure that's quite easy to use.
Keep in mind, though, that this is not the only way to go for apps. You can, of course, use different services, providers or host everything on a dedicated machine. This guide explains to you how to get started for hosting an app on Platform.sh.
Know more about hosting from the hosting guide and from the official documentation.
Getting started
To deploy your app on Platform.sh, just follow those instructions:
Most important steps
- Configure your Source Integrations (Optional, but highly recommended!)
- Install the Platform.sh CLI
- Authenticate using your Platform.sh account
- Create required config files. Also, if you create a new project, Platform.sh shows you a checklist where you can generate the code for these files
- Push your changes to your Git Repo
- After it's been deployed, migrate the database by connecting via SSH to your project and running the command
vendor/bin/doctrine-migrations migrations:migrate
- That's it!
Your project should now be running at https://console.platform.sh, and you can start developing your own app!
Good to know
Automatic TLS certificates based on Branch / Pull Request
Platform.sh automatically creates a URL and TLS certificate using Let's Encrypt based on your routes.yaml file for every active environment.
You should be aware that the URL will be built in a specific way. If your branch name gets too long, Let's Encrypt won't be able to generate a certificate.
To avoid this, you should configure your Source Integrations to use the name of your Pull Request instead of the Branch Name.
Read more about this topic from doc.platform.sh.
Hook commands
You can place commands like the database migration mentioned above inside your .platform.app.yaml
under hooks. This way your commands will be executed every time it deploys a new build (e.g. if your branch gets updated).
Your file could than look like this (with the default AppTemplate):
// .platform.app.yaml
hooks:
build: |
set -e
php bin/console assets:install --no-debug
deploy: |
set -e
php bin/console cache:clear
php bin/console doctrine:migrations:migrate --no-interaction
By default, PHP images already run a composer install
command, so we don't need that in our hooks. Learn more about that here.
Useful Platform.sh commands
In order to use the following commands you need to have the Platform.sh CLI installed.
List all Platform.sh CLI commands
platform list
Set Platform.sh as new remote host
This step is needed if you want to get more information about the project using the Platform.sh CLI.
Refer to this documentation on Create environment
platform project:set-remote <Project ID>
Push single branch to Platform.sh and activate it
Refer to this documentation on Create environment
# Push to Platform.sh
git push -u platform <Branch Name>
# Activate branch
platform environment:activate <Branch Name>
Get available URLs for the current project
Refer to this Documentation
platform url
SSH into your project
Refer to this documentation on SSH
platform ssh
Connect to the database using SSH tunneling
Refer to this documentation on SSH Tunneling
# List all possible commands
platform tunnel:list
# Open tunnel for all services
platform tunnel:open
# Connect to the remote database normally, as if it were local.
mysql --host=127.0.0.1 --port=30001 --user='user' --password='' --database='main'
Accessing log files
Refer to this documentation on logs
platform log --help