Run a PHP script using GitHub Actions

Below instructions on setting up an automated GitHub actions workflow that runs some PHP

  • SignUp and Create a new reposiory in Github

  • Add a php file to your repository root named PHPTest.php image.png

  • Add some php in to file

    echo "testing";
  • Commit and push this file into repository

  • Create new file in your GitHub repo like this path

  • Add below code to yml file

# This is a basic workflow to help you get started with Actions

name: RunPHP

# Controls when the action will run. 
  # Triggers the workflow on push of repository
    branches: [ main ]
  # Can add a schedule cron of when to run action but leaving this commented out for now
  #  - cron: '0 08 * * *' 
  # Allows you to run this workflow manually from the Actions tab

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
  # This workflow contains a single job called "build"
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # PHP GitHub Action created by
    - uses: actions/checkout@master
    - uses: nanasess/setup-php@master
        php-version: '7.4'
    # This triggers our php file we created before
    - run: php ./PHPTest.php
  • Commit and Push your changes and click actions on your repo.

  • Click on Actions in your repository

  • You should see it building and if successful you can see php script returning "testing"


  • After you get this working you can modify your PHPTest.php file to do whatever you want!

Hope this works for you. Let me know if you get stuck.

Happy Coding, Asrin

If this helped you consider buying me a coffee :)


Did you find this article valuable?

Support Asrin Dayananda by becoming a sponsor. Any amount is appreciated!