PHP: Configuring the GitHub Actions workflow

This documentation is part of the Deploying PHP Applications with GitHub Actions guide. You can view the complete guide here: How to deploy your PHP code using GitHub Actions.

👋 Welcome to the Stackhero documentation!

Stackhero offers managed PHP hosting 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 set up for you. No manual intervention required.
  • Take advantage of automatic backups, one-click updates, and straightforward, predictable pricing. Stackhero manages these aspects so you can focus on your code.
  • Enjoy robust performance and security on a private, dedicated infrastructure tailored specifically for your applications.

Streamline your workflow and save time. Getting started with Stackhero's PHP hosting for Laravel and Symfony only takes a few minutes.

Now you will set up a GitHub Actions workflow file to automate your deployments. Within your Git repository, create a directory named .github/workflows and add a file called deploy-to-stackhero.yml with the following content:

# File: .github/workflows/deploy-to-stackhero.yml

name: Deploy to Stackhero
run-name: Deploy branch "${{ github.ref_name }}" to Stackhero

on:
  push:
    # List of branches that will trigger the deploy action following a git push
    # Do not forget to create a corresponding environment in GitHub (under "Settings" -> "Environments") for each branch
    # Then add the secret "STACKHERO_SSH_PRIVATE_KEY" and variable "STACKHERO_ENDPOINT" in that environment
    branches: [ "production", "staging" ]

jobs:
  Deploy:
    environment: ${{ github.ref_name }}
    runs-on: ubuntu-latest
    steps:
    - uses: stackhero-io/github-actions-deploy-to-stackhero@v1
      with:
        # The secret "STACKHERO_SSH_PRIVATE_KEY" and the variable "STACKHERO_ENDPOINT" should be defined in the corresponding GitHub environment (under "Settings" -> "Environments")
        ssh_private_key: ${{ secrets.STACKHERO_SSH_PRIVATE_KEY }}
        endpoint: ${{ vars.STACKHERO_ENDPOINT }}

Once you have added this file, you can commit your changes by running the following commands in your terminal:

git add -A .
git commit -m "Add GitHub Actions to deploy to Stackhero"

To create the production branch, you can run:

git checkout -b production

Then push your changes to GitHub:

git push --set-upstream origin production

This will push your code to the production branch on GitHub. GitHub Actions will then automatically run and deploy your code to the associated Stackhero instance. To check the deployment status, go to your GitHub project and click on Actions.

GitHub Actions that deployed to productionGitHub Actions that deployed to production

Congratulations! Your project is now configured for automatic deployment to production using GitHub Actions.