How can we configure PlanetScale with App Platform?

I would like to use PlanetScale with my App Platform app, how can I configure it to use the proxy that is required?

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Please, do NOT follow the answer from Jon Friesen anymore. It was probably written before PlanetScale implement its connection strings feature.


  1. Create a password for your database
  2. Add the details of your password as env variables for Laravel (DB_HOST, DB_PASSWORD, DB_USER, DB_DATABASE, DB_USER, DB_PORT is 3306) in DigitalOcean web console You should use the web panel and mark your password as “encrypted”.
  3. Add MYSQL_ATTR_SSL_CA env variable also with the value /etc/ssl/certs/ca-certificates.crt
  4. Promote a branch to be your production branch

You can also find more details here

Jon Friesen
DigitalOcean Employee
DigitalOcean Employee badge
August 13, 2021


Great question! Since PlanetScale has a neat client that creates a proxy to the database instance, we will have to install and authenticate that tool so that it can inject a DATABASE_URL environment variable into the app.

  1. Setup a service token using this PlanetScale tutorial
  2. The app component that will be connecting to your PlanetScale database will need to have it’s build command altered to install the client like so:
export PSCALE_VERSION="$(curl -s -L -I -o /dev/null -w '%{url_effective}' | awk '{n=split($1,A,"/v"); print A[n]}')" && \
curl -sL$PSCALE_VERSION/pscale_${PSCALE_VERSION}_linux_amd64.tar.gz | tar -xz -C ./ && \
chmod +x ./pscale
  1. We will also need to wrap the run command in the PlanetScale command for URL injection like so:
./pscale connect app-platform-test main --execute "node app.js"

Don’t forget to set the required PlanetScale environment variables from the tutorial!


And that’s it! PlanetScale connections in App Platform! If you want to support PlanetScale with an a dockerfile based app add the install command above prefixed with RUN to your dockerfile, for example:

export PSCALE_VERSION="$(curl -s -L -I -o /dev/null -w '%{url_effective}' | awk '{n=split($1,A,"/v"); print A[n]}')" && \
curl -sL$PSCALE_VERSION/pscale_${PSCALE_VERSION}_linux_amd64.tar.gz | tar -xz -C ./ && \
chmod +x ./pscale

Don’t forget to ensure your run command is wrapped in the pscale connect... command :)

Here’s an example app spec:

name: pscale-express-example
region: nyc
- build_command: |-
    export PSCALE_VERSION="$(curl -s -L -I -o /dev/null -w '%{url_effective}' | awk '{n=split($1,A,"/v"); print A[n]}')" && \
    curl -sL$PSCALE_VERSION/pscale_${PSCALE_VERSION}_linux_amd64.tar.gz | tar -xz -C ./ && \
    chmod +x ./pscale
  environment_slug: node-js
    value: <org>
    value: <service_token_name>
    value: <service_token>
    branch: main
    deploy_on_push: true
    repo: planetscale/express-example
  http_port: 8080
  instance_count: 1
  instance_size_slug: basic-xs
  name: pscale-express-example
  - path: /
  run_command: ./pscale connect <database_name> main --execute "node app.js"
  source_dir: /

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel