Intermediate 2: The Platform.sh CLI
Overview
The Platform.sh command line interface will be your primary tool (along with the management console UI) for interacting with your projects and environments. Everything that can be done over the API can be done through the CLI once you install it.
To install, check the documentation for the latest instructions.
Then authenticate the CLI with your account by running the command
platform
and view a full list of available commands
platform list
Some examples
Given a project and environment IDs, you can run the following commands to modify a project:
- Grab an application’s configuration:
platform app:config-get -p PROJECT_ID - Create a backup of an environment:
platform backup:create -p PROJECT_ID -e ENVIRONMENT_ID - Dump an environment’s database:
platform db:dump -p PROJECT_ID -e ENVIRONMENT_ID - Start a SQL session with a database container:
platform db:sql -p PROJECT_ID -e ENVIRONMENT_ID - Add a domain to a project:
platform domain:add -p PROJECT_ID -e ENVIRONMENT_ID - Activate an environment post-push:
platform environment:activate -p PROJECT_ID -e ENVIRONMENT_ID - Read an environment’s logs:
platform environment:logs -p PROJECT_ID -e ENVIRONMENT_ID - Redeploy an environment:
platform environment:redeploy -p PROJECT_ID -e ENVIRONMENT_ID - Synchronize data from the parent environment:
platform environment:synchronize data -p PROJECT_ID -e ENVIRONMENT_ID - Synchronize both code AND data from the parent environment:
platform environment:synchronize code data -p PROJECT_ID -e ENVIRONMENT_ID - Add an environment-level variable:
platform variable:create -l environment --name=FOO --value=BAR -p PROJECT_ID -e ENVIRONMENT_ID - Add a project-level variable:
platform variable:create -l project --name=FOO --value=BAR -p PROJECT_ID -e ENVIRONMENT_ID
There are many more useful commands you can use to interact with and troubleshot environments and projects on Platform.sh.
One of the interesting ones is project:curl, which gives you access to some of the broader API requests available via our API documentation at api.platform.sh. For example, activating an environment using this command would look like:
platform project:curl -p PROJECT_ID /environments/ENVIRONMENT_ID/activate
It’s recommended to use the CLI commands directly, but this particular command can be useful, such as when a JSON response is desirable.
Next: The Platform.sh API
Comments
Please sign in to leave a comment.