Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

baspa's avatar
Level 1

How to add deploy keys from two sites into one Github repository?

I have one server on my Forge account with two sites. One is a production site while the other is a staging website. For example:

  • domain.com
  • test.domain.com

Both rely on the same Github repository, the staging site should be deployed when a commit is pushed to the develop branch while production should be deployed when anything is pushed to the main branch.

What did I do:

I added the deployment hook of both sites into the secrets of the Github repository:

  • FORGE_DEPLOYMENT_HOOK_PRODUCTION
  • FORGE_DEPLOYMENT_HOOK_STAGING

Then I created a Github action for both sites which starts on push to either branch and makes a curl request to the deployment hook:

name: Deploy production

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Deploy Site
        run: curl ${{ secrets.FORGE_DEPLOYMENT_HOOK_PRODUCTION }}

I added the site’s deploy key of the production site (domain.com) to the repository deploy keys. When I try to add the staging key (test.domain.com) I get the error: Key is already in use. If I check the key it is actually a different key except for the first x amount of characters. Because I can’t add the key the action only works for the production site and not the staging site. I get this error when deploying staging:

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

So my question is: how can I add the second deploy key? And if this is not possible, what would be the best way to setup my Github actions to achieve the same goal? I thought this to be the easiest way.

0 likes
0 replies

Please or to participate in this conversation.