Home

Awesome

php-windows-builder

This project provides actions to build PHP and its extensions on Windows.

Build PHP

Build PHP for a specific version, architecture and thread safety.

- name: Build PHP
  uses: php/php-windows-builder/php@v1
  with:
    php-version: '8.4.1'
    arch: x64
    ts: nts

Inputs

Example workflow to build PHP

jobs:
  php:
    strategy:
      matrix:
        arch: [x64, x86]
        ts: [nts, ts]
    runs-on: windows-2019
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Build
        uses: php/php-windows-builder/php@v1
        with:
          php-version: '8.4.1'
          arch: ${{ matrix.arch }}
          ts: ${{ matrix.ts }}

The above workflow will produce the following the following builds for the PHP version 8.3.2 as artifacts.

Build a PHP extension

Build a PHP extension for a specific version.

- name: Build the extension
  uses: php/php-windows-builder/extension@v1
  with:
    extension-url: https://github.com/xdebug/xdebug
    extension-ref: '3.3.2'
    php-version: '8.3'
    ts: nts
    arch: x64
    args: --with-xdebug
    libs: zlib

Inputs

Instead of having to configure all the inputs for the extension action, you can use the extension-matrix action to get the matrix of jobs with different input configurations.

Get the job matrix to build a PHP extension

jobs:
  get-extension-matrix:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Get the extension matrix
        id: extension-matrix
        uses: php/php-windows-builder/extension-matrix@v1
        with:
          extension-url: https://github.com/xdebug/xdebug
          extension-ref: '3.3.2'
          php-version-list: '8.2, 8.3'
          arch-list: 'x64, x86'
          ts-list: 'nts, ts'

Inputs

Outputs

PHP Version Support

By default, the extension-matrix action will use the PHP versions defined in the php-version-list input.

If the php-version-list input is not provided, it will use the PHP versions required in the composer.json file.

It will also check if a GitHub hosted Windows runner is available with the required Visual Studio version to build the extension for the PHP version. To override this for building the extension for older PHP versions, you will have to set the input allow_old_php_versions to true and add self-hosted Windows runners as specified in the table below.

PHP VersionVisual Studio VersionWindows Runner Labels
7.02015 (vc14)windows-2012, self-hosted
7.12015 (vc14)windows-2012, self-hosted
7.22017 (vc15)windows-2019, github-hosted
7.32017 (vc15)windows-2019, github-hosted
7.42017 (vc15)windows-2019, github-hosted
8.02019 (vs16)windows-2019, github-hosted
8.12019 (vs16)windows-2019, github-hosted
8.22019 (vs16)windows-2019, github-hosted
8.32019 (vs16)windows-2019, github-hosted
8.42022 (vs17)windows-2022, github-hosted

Release

Upload the artifacts to a release.

- name: Upload artifact to the release
  uses: php/php-windows-builder/release@v1
  with:
    release: ${{ github.event.release.tag_name }}
    token: ${{ secrets.GITHUB_TOKEN }}

Inputs

Example workflow to build and release an extension

name: Build extension
on:
  release:
    types: [published]
  # create: # Uncomment this to run on tag/branch creation
  # pull_request: # Uncomment this to run on pull requests  

# This may be needed to be able to upload the assets to the release
# See: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
#permissions:
#  contents: write

jobs:
  get-extension-matrix:
    runs-on: ubuntu-latest
    outputs:
      matrix: ${{ steps.extension-matrix.outputs.matrix }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Get the extension matrix
        id: extension-matrix
        uses: php/php-windows-builder/extension-matrix@v1
  build:
    needs: get-extension-matrix
    runs-on: ${{ matrix.os }}
    strategy:
      matrix: ${{fromJson(needs.get-extension-matrix.outputs.matrix)}}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Build the extension
        uses: php/php-windows-builder/extension@v1
        with:
          php-version: ${{ matrix.php-version }}
          arch: ${{ matrix.arch }}
          ts: ${{ matrix.ts }}
  release:
    runs-on: ubuntu-latest
    needs: build
    if: ${{ github.event_name == 'release' }}
    steps:
      - name: Upload artifact to the release
        uses: php/php-windows-builder/release@v1
        with:
          release: ${{ github.event.release.tag_name }}
          token: ${{ secrets.GITHUB_TOKEN }}

License

The scripts and documentation in this project are released under the MIT License