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 offers a ready-to-use PHP cloud solution that provides a host of benefits, including:
- Deploy your application in seconds with a simple
git push.- Use your own domain name and benefit from the automatic configuration of HTTPS certificates for enhanced security.
- Enjoy peace of mind with automatic backups, one-click updates, and straightforward, transparent, and predictable pricing.
- Get optimal performance and robust security thanks to a private and dedicated VM.
Save time and simplify your life: it only takes 5 minutes to try Stackhero's PHP cloud hosting solution!
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.
Generate SSH keys
To generate new SSH keys, you can run this command on your computer:
ssh-keygen -C "" -f /tmp/ssh_key -N ""
Set the public key
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:
- Under
SSH public keys, click on "Add a public key". - Set the
Descriptionto "GitHub Action". - Paste the public key you just retrieved into the
Keyfield.
Get service settings
Set the private key
Now, add the private key to your GitHub project so it can be used during deployment:
-
Go to
Settings, then selectEnvironmentsand click onNew environment.
Configuring GitHub environments -
In the
Namefield, enter "production" and confirm.
Setting the environment -
Click on the
No restrictionbutton and selectSelected branches and tags.
Setting environment restrictions -
Click on
Add deployment branch or tag rule, enter "production" in theName patternfield, and click onAdd rule.
Setting environment branch
Setting environment branch -
Under
Environment secrets, click onAdd secret.
Add secret
Retrieve the private key you generated earlier by running:
cat /tmp/ssh_key
In the GitHub environment settings:
-
For
Name, enterSTACKHERO_SSH_PRIVATE_KEYand paste your private key into theValuefield.
Setting the SSH private key secret -
In the
Environment variablessection, click onAdd variable.
Setting variables -
For
Name, enterSTACKHERO_ENDPOINTand paste your PHP service endpoint into theValuefield. You can find this endpoint in your Stackhero dashboard.
Setting the endpoint variable
If you have customised your service's domain name, use the customised version instead of <XXXXXX>.stackhero-network.com.
Delete the generated keys
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