Platform.sh User Documentation

Tethered local development

Upsun Beta

Access our newest offering - Upsun!

Get your free trial by clicking the link below.

Get your Upsun free trial

To test changes locally, you can connect your locally running web server to service containers on an active Platform.sh environment. This method requires less configuration than tools such as DDEV, but may not perform well enough for everyday use. Because it replies on a local web server, it’s also less consistent across your team.

Before you begin Anchor to this heading

You need:

  • A local copy of the repository for a project running on Platform.sh.

    To get one, run platform get PROJECT_ID .

    Alternatively, you can clone an integrated source repository and set the remote branch. To do so, run platform project:set-remote PROJECT_ID .

  • The Platform.sh CLI

Create the tethered connection Anchor to this heading

  1. Create a new environment based on production.

    platform branch new-feature PRODUCTION_ENVIRONMENT_NAME

    If you’re using a source integration, open a merge/pull request.

  2. To open an SSH tunnel to the new environment’s services, run the following command:

    platform tunnel:open

    This command returns the addresses for SSH tunnels to all of your services.

  3. Export the PLATFORMSH_RELATIONSHIPS environment variable with information from the open tunnel:

    export PLATFORM_RELATIONSHIPS="$(platform tunnel:info --encode)"
  1. Run your application locally. Make sure it’s set up to read configuration from Platform.sh environment variables.

    If you app relies on other Platform.sh environment configuration, such as routes or secret variables, make sure to mock those variables as well.

    Your options for running the app depend on the language and configuration. You can use the server for your language, install a copy of Nginx, or use a virtual machine or Docker image.

  1. When you’ve finished your work, close the tunnels to your services by running the following command:

    platform tunnel:close --all -y

Connect to services directly Anchor to this heading

With open tunnels to all your services, you can also connect to the running services directly. To get information on all running services, run the following command:

platform tunnels

You get a response similar to the following:

+-------+---------------+-------------+-----+--------------+
| Port  | Project       | Environment | App | Relationship |
+-------+---------------+-------------+-----+--------------+
| 30000 | abcdefg123456 | new-feature | app | cache        |
| 30001 | abcdefg123456 | new-feature | app | database     |
+-------+---------------+-------------+-----+--------------+

You can use the port information to connect directly to a service. If you need more detailed information, such as a path or password, run the following command:

platform tunnel:info

You can use the information returned to connect to the remote database as if it were local. For example, the following command would connect to a MySQL database running through a tethered connection:

mysql --host=127.0.0.1 --port=PORT --user=USERNAME --password=PASSWORD --database=PATH

Next steps Anchor to this heading

You can now use your local environment to develop changes for review on Platform.sh environments. The following examples show how you can take advantage of that.

Onboard collaborators Anchor to this heading

It’s essential for every developer on your team to have a local development environment to work on. Place the local configuration into a script to ensure everyone has this. You can merge this change into production.

  1. Create a new environment called local-config.

  2. To set up a local environment for a new Platform.sh environment, create an executable script.

    touch init-local.sh && chmod +x init-local.sh
Fill it with something similar to the following example, depending on your app and configuration:

```bash {location="init-local.sh"}
#!/usr/bin/env bash

ENVIRONMENT=$1
PARENT=$2

# Create the new environment
platform branch $ENVIRONMENT $PARENT

# Open a tunnel to the current environment
platform tunnel:open --no-interaction

# Mock Platform.sh environment variables
export PLATFORM_RELATIONSHIPS="$(platform tunnel:info --encode)"
# Add any other variables you need

# If necessary, install dependencies here

# Add the command to run the server

```
  1. To commit and push the revisions, run the following command:

    git add . && git commit -m "Add local configuration" && git push platform local-config
  2. Merge the change into production.

    Once the script is merged into production, any user can set up their local environment by running the following commands:

    platform PROJECT_ID
    cd PROJECT_NAME
    ./init-local.sh PROJECT_ID another-new-feature PRODUCTION_ENVIRONMENT_NAME

Is this page helpful?