Skip to main content
setup-php exposes output values you can reference in later steps of your workflow. To access outputs, assign an id to the setup-php step and reference it using the steps.<id>.outputs.<name> expression.
- name: Setup PHP
  id: setup-php
  uses: shivammathur/setup-php@v2
  with:
    php-version: '8.5'

- name: Use PHP version output
  run: echo "PHP version is ${{ steps.setup-php.outputs.php-version }}"

php-version
string
required
The PHP version that was set up, in semver format (e.g. 8.5.4).This is useful when you specify a non-exact version like latest, 8.x, or highest and need to know the exact version that was installed — for example, to use it as a cache key or to log it in your workflow summary.

Example: capturing and printing the PHP version

steps:
  - name: Setup PHP
    id: setup-php
    uses: shivammathur/setup-php@v2
    with:
      php-version: '8.5'

  - name: Print PHP version
    run: echo ${{ steps.setup-php.outputs.php-version }}

Example: using the version as a cache key

steps:
  - name: Setup PHP
    id: setup-php
    uses: shivammathur/setup-php@v2
    with:
      php-version: 'latest'
      extensions: imagick, redis

  - name: Cache extensions
    uses: actions/cache@v4
    with:
      path: ~/.php-extensions
      key: php-${{ steps.setup-php.outputs.php-version }}-extensions

Build docs developers (and LLMs) love