PHP: Configure SSH keys

This documentation is part of the Deploy with GitHub Actions guide. View the full guide here: How to deploy your PHP code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero provides a PHP cloud platform designed for fast, reliable deployments:

  • Deploy your PHP application to production in seconds with a simple git push.
  • Use your own domain, with automatic HTTPS certificates configured for you. There are no manual steps needed.
  • Rely on automatic backups, one-click updates, and clear, predictable pricing. Stackhero handles these details, so you can focus on your code.
  • Benefit from strong performance and security on a private, dedicated infrastructure built specifically for your applications.

Make your workflow smoother and save time. Getting started with Stackhero's PHP cloud hosting takes just a few minutes.

SSH keys are the recommended method for allowing GitHub Actions to securely connect to your PHP service during deployment. In this guide, you will create a unique SSH key pair just for this purpose.

To generate new SSH keys, you can run this command on your computer:

ssh-keygen -C "" -f /tmp/ssh_key -N ""

Next, retrieve the public key by running:

cat /tmp/ssh_key.pub

Head over to your Stackhero dashboard and select your "Production" PHP service. Click on "Configure" and follow these steps:

  1. Under SSH public keys, click on "Add a public key".
  2. Set the Description to "GitHub Action".
  3. Paste the public key you just retrieved into the Key field.

Get service settingsGet service settings

Now, add the private key to your GitHub project so it can be used during deployment:

  • Go to Settings, then select Environments and click on New environment.

    Configuring GitHub environmentsConfiguring GitHub environments

  • In the Name field, enter "production" and confirm.

    Setting the environmentSetting the environment

  • Click on the No restriction button and select Selected branches and tags.

    Setting environment restrictionsSetting environment restrictions

  • Click on Add deployment branch or tag rule, enter "production" in the Name pattern field, and click on Add rule.

    Setting environment branchSetting environment branch Setting environment branchSetting environment branch

  • Under Environment secrets, click on Add secret.

    Add secretAdd secret

Retrieve the private key you generated earlier by running:

cat /tmp/ssh_key

In the GitHub environment settings:

  • For Name, enter STACKHERO_SSH_PRIVATE_KEY and paste your private key into the Value field.

    Setting the SSH private key secretSetting the SSH private key secret

  • In the Environment variables section, click on Add variable.

    Setting variablesSetting variables

  • For Name, enter STACKHERO_ENDPOINT and paste your PHP service endpoint into the Value field. You can find this endpoint in your Stackhero dashboard.

    Setting the endpoint variableSetting the endpoint variable

If you have customised your service's domain name, use the customised version instead of <XXXXXX>.stackhero-network.com.

For security reasons, it is a good idea to remove the generated SSH keys from your computer after setup:

rm /tmp/ssh_key /tmp/ssh_key.pub