### Setup PHP with Fail-Fast for Extension Installation Source: https://github.com/shivammathur/setup-php/blob/main/README.md Configures the setup-php action to fail immediately if an extension installation error occurs. This is useful for catching critical issues early. ```yaml - name: Setup PHP with fail-fast uses: shivammathur/setup-php@v2 with: php-version: '8.5' extensions: oci8 env: fail-fast: true ``` -------------------------------- ### Setup PHP with Psalm Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP 8.5 and the Psalm tool. Run Psalm analysis with GitHub Actions output format. ```yaml - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: psalm - name: Run Psalm run: psalm --output-format=github ``` -------------------------------- ### Setup PHP with Protobuf Extension from Sub-directory Source: https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source Installs the protobuf extension from a repository where the extension source is located in a sub-directory. The PROTOBUF_PATH environment variable specifies the location. ```yaml name: Setup PHP with protobuf from source uses: shivammathur/setup-php@v2 with: php-version: '7.4' extensions: protobuf-protocolbuffers/protobuf@v3.15.2 env: PROTOBUF_PATH: php/ext/google/protobuf ``` -------------------------------- ### Setup PHP with PHPStan Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP 8.5 and the PHPStan tool. Run PHPStan analysis. ```yaml - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: phpstan - name: Run PHPStan run: phpstan analyse src ``` -------------------------------- ### Setup PHP with Xdebug Source: https://github.com/shivammathur/setup-php/blob/main/README.md Use this snippet to set up PHP with the Xdebug coverage driver. The latest compatible Xdebug version is installed by default. ```yaml - name: Setup PHP with Xdebug uses: shivammathur/setup-php@v2 with: php-version: '8.5' coverage: xdebug ``` -------------------------------- ### Setup PHP with MongoDB Extension from GitHub Source Source: https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source Installs the mongodb extension from its GitHub repository using a specific tag. Ensure the repository and tag are valid. ```yaml name: Setup PHP with mongodb from source uses: shivammathur/setup-php@v2 with: php-version: '8.2' extensions: mongodb-mongodb/mongo-php-driver@1.15.0 ``` -------------------------------- ### Setup PHP with HTTP Extension with Custom Configurations Source: https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source Installs the http extension with custom build configurations. HTTP_CONFIGURE_PREFIX_OPTS sets compiler flags, and HTTP_CONFIGURE_OPTS provides configure script arguments. ```yaml name: Setup PHP with http from source uses: shivammathur/setup-php@v2 with: php-version: '8.0' extensions: raphf, http-m6w6/ext-http@v4.0.0 env: HTTP_CONFIGURE_PREFIX_OPTS: "CFLAGS=-Wno-implicit-function-declaration" HTTP_CONFIGURE_OPTS: "--with-http" ``` -------------------------------- ### Setup PHP with Fail-Fast Enabled Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP version 8.5 and the deployer tool, with the 'fail-fast' option enabled. This will stop the workflow on the first tool setup failure. ```yaml - name: Setup PHP with fail-fast uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: deployer env: fail-fast: true ``` -------------------------------- ### Setup PHP without Composer Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP version 8.5 and explicitly skips the setup of composer. Use this if composer is not needed in your workflow. ```yaml - name: Setup PHP without composer uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: none ``` -------------------------------- ### Self-Hosted PHP Setup Source: https://github.com/shivammathur/setup-php/blob/main/README.md Configure PHP setup on a self-hosted runner by setting the 'runner' environment variable to 'self-hosted'. This example supports a matrix of PHP versions. ```yaml jobs: run: runs-on: self-hosted strategy: matrix: php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'] name: PHP ${{ matrix.php-versions }} steps: - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} env: runner: self-hosted ``` -------------------------------- ### Setup PHP with PHPCS and cs2pr Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP 8.5, PHPCS, and cs2pr. Runs PHPCS and pipes output to cs2pr for pull request annotations. ```yaml - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: cs2pr, phpcs - name: Run phpcs run: phpcs -q --report=checkstyle src | cs2pr ``` -------------------------------- ### Basic PHP Setup Source: https://github.com/shivammathur/setup-php/blob/main/README.md Sets up a specific PHP version with extensions, ini values, coverage, and tools. ```yaml steps: - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' extensions: mbstring, intl ini-values: post_max_size=256M, max_execution_time=180 coverage: xdebug tools: php-cs-fixer, phpunit ``` -------------------------------- ### Setup PHP with CSV Extension from GitLab Source Source: https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source Installs the csv extension from a GitLab repository using a specific version tag. This demonstrates using a Git provider other than GitHub. ```yaml name: Setup PHP with csv from source uses: shivammathur/setup-php@v2 with: php-version: '7.4' extensions: csv-https://gitlab.com/Girgias/csv-php-extension@0.3.1 ``` -------------------------------- ### Setup PHP with Specific Composer Tool Version Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP version 8.5 and composer version 2. This demonstrates how to specify exact or partial versions for tools. ```yaml - name: Setup PHP with composer v2 uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: composer:v2 ``` -------------------------------- ### Setup PHP with Redis Extension and LZ4 Support (Cross-Platform) Source: https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source Installs the redis extension with LZ4 support in a cross-platform workflow. It dynamically determines the liblz4 directory and specifies necessary libraries for Linux and macOS. ```bash if [ "$(uname -s)" = "Linux" ]; then echo "lz4_dir=/usr" >> "$GITHUB_OUTPUT" else echo "lz4_dir=$(brew --prefix)/opt/lz4" >> "$GITHUB_OUTPUT" fi ``` ```yaml name: Setup PHP with redis from source with lz4 support uses: shivammathur/setup-php@v2 with: php-version: '8.0' extensions: redis-phpredis/phpredis@5.3.7 env: REDIS_CONFIGURE_OPTS: --enable-redis --enable-redis-lz4 --with-liblz4=${{ steps.lz4.outputs.lz4_dir }} REDIS_LINUX_LIBS: liblz4-dev REDIS_DARWIN_LIBS: lz4 ``` -------------------------------- ### Setup PHP with Pre-release PECL Extension Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs a pre-release version (beta) of the xdebug extension from PECL for PHP 8.5. Supports 'alpha', 'beta', 'devel', or 'snapshot' states. ```yaml - name: Setup PHP with pre-release PECL extension uses: shivammathur/setup-php@v2 with: php-version: '8.5' extensions: xdebug-beta ``` -------------------------------- ### Install Docker on Linux Source: https://github.com/shivammathur/setup-php/wiki/Requirements-for-self-hosted-runners Installs Docker using a convenience script and grants the runner user read-write access to the Docker socket. Required for workflows using Docker services. ```bash curl https://get.docker.com | sh sudo chmod o+rw /var/run/docker.sock ``` -------------------------------- ### Setup PHP with PECL Extension Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs imagick and redis extensions from PECL for PHP 8.5. Ensure these extensions are available as packages or on PECL. ```yaml - name: Setup PHP with PECL extension uses: shivammathur/setup-php@v2 with: php-version: '8.5' extensions: imagick, redis ``` -------------------------------- ### Setup PHP with Composer Plugin Allow List Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP version 8.5 and sets the COMPOSER_ALLOW_PLUGINS environment variable to a CSV list of allowed composer plugins. This is necessary when installing composer plugins via the 'tools' input or if dependencies have composer plugins. ```yaml - name: Setup PHP with fail-fast uses: shivammathur/setup-php@v2 with: php-version: '8.5' env: COMPOSER_ALLOW_PLUGINS: composer/installers, composer/satis ``` -------------------------------- ### Setup PHP with Composer and Custom Process Timeout Source: https://github.com/shivammathur/setup-php/blob/main/README.md Use this snippet to install a specific PHP version and configure Composer's process timeout. Ensure the `php-version` is compatible with the action. ```yaml - name: Setup PHP with composer and custom process timeout uses: shivammathur/setup-php@v2 with: php-version: '8.5' env: COMPOSER_PROCESS_TIMEOUT: 300 ``` -------------------------------- ### Setup PHP with Composer Package Tool Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP version 8.5 and a specific composer package (vimeo/psalm) as a global tool. This allows using tools listed on Packagist directly. ```yaml - name: Setup PHP with tools uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: vimeo/psalm ``` -------------------------------- ### Verbose PHP Setup Source: https://github.com/shivammathur/setup-php/blob/main/README.md Use the 'verbose' tag for detailed logs during PHP setup. This is helpful for debugging workflow issues. ```yaml - name: Setup PHP with logs uses: shivammathur/setup-php@verbose with: php-version: '8.5' ``` -------------------------------- ### Setup PHP with Multiple Tools Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs PHP version 8.5 and the php-cs-fixer and phpunit tools. This is useful for setting up common development tools globally for CI workflows. ```yaml - name: Setup PHP with tools uses: shivammathur/setup-php@v2 with: php-version: '8.5' tools: php-cs-fixer, phpunit ``` -------------------------------- ### Matrix PHP Setup Source: https://github.com/shivammathur/setup-php/blob/main/README.md Configures multiple PHP versions across different operating systems using a matrix strategy for CI/CD pipelines. ```yaml jobs: run: runs-on: ${{ matrix.operating-system }} strategy: matrix: operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest'] php-versions: ['8.2', '8.3', '8.4', '8.5'] phpunit-versions: ['latest'] include: - operating-system: 'ubuntu-latest' php-versions: '8.1' phpunit-versions: 10 steps: - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} extensions: mbstring, intl ini-values: post_max_size=256M, max_execution_time=180 coverage: xdebug tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }} ``` -------------------------------- ### Nightly PHP Build Setup Source: https://github.com/shivammathur/setup-php/blob/main/README.md Sets up a nightly build of PHP, which may contain bugs or breaking changes. Use with caution. ```yaml steps: - name: Setup nightly PHP uses: shivammathur/setup-php@v2 with: php-version: '8.6' extensions: mbstring ini-values: post_max_size=256M, max_execution_time=180 coverage: xdebug tools: php-cs-fixer, phpunit ``` -------------------------------- ### Install 7-Zip for Composer on Windows Source: https://github.com/shivammathur/setup-php/wiki/Requirements-for-self-hosted-runners Installs Chocolatey package manager and then installs 7-Zip. This can speed up Composer operations on Windows. ```powershell # Install choco $installScript = Invoke-WebRequest -Uri "https://community.chocolatey.org/install.ps1" -UseBasicParsing & ([scriptblock]::Create($installScript)) # Install 7-Zip choco install -y --force 7zip.install ``` -------------------------------- ### Setup PHP with Xdebug 2.x Source: https://github.com/shivammathur/setup-php/blob/main/README.md Use this snippet to specifically set up Xdebug version 2.x on PHP 7.2, 7.3, or 7.4. ```yaml - name: Setup PHP with Xdebug 2.x uses: shivammathur/setup-php@v2 with: php-version: '7.4' coverage: xdebug2 ``` -------------------------------- ### Thread Safe PHP Setup Source: https://github.com/shivammathur/setup-php/blob/main/README.md Sets up a thread-safe (TS) build of PHP. Non-thread-safe (NTS) is the default. ```yaml jobs: run: runs-on: [ubuntu-latest, windows-latest, macos-latest] name: Setup PHP TS steps: - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' env: phpts: ts # specify ts or nts ``` -------------------------------- ### Setup Problem Matchers for PHPUnit Source: https://github.com/shivammathur/setup-php/blob/main/README.md Add problem matchers for PHPUnit output to highlight errors and warnings in the GitHub Actions UI. This step should be added after the setup-php step. ```yaml - name: Setup problem matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" ``` -------------------------------- ### Setup PHP with Manual Composer Authentication Source: https://github.com/shivammathur/setup-php/blob/main/README.md Authenticate with private repositories hosted elsewhere using the COMPOSER_AUTH_JSON environment variable. This allows for custom authentication methods. ```yaml - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' env: COMPOSER_AUTH_JSON: | { "http-basic": { "example.org": { "username": "${{ secrets.EXAMPLE_ORG_USERNAME }}", "password": "${{ secrets.EXAMPLE_ORG_PASSWORD }}" } } } ``` -------------------------------- ### Cache Composer Dependencies Source: https://github.com/shivammathur/setup-php/blob/main/README.md Cache Composer dependencies to speed up workflow execution. This example shows how to get the cache directory, cache the dependencies, and then install them. ```yaml - name: Get composer cache directory id: composer-cache run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - name: Cache dependencies uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} restore-keys: ${{ runner.os }}-composer- ``` ```yaml - name: Install dependencies run: composer install --prefer-dist ``` -------------------------------- ### Print PHP Version Output Source: https://github.com/shivammathur/setup-php/blob/main/README.md Demonstrates how to retrieve and print the PHP version output from the setup-php action in a subsequent step. ```yaml - 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 }} ``` -------------------------------- ### Migrating from setup-php v1 to v2 Source: https://github.com/shivammathur/setup-php/wiki/Switch-to-v2 This diff shows the changes required to switch from setup-php v1 to v2. It includes renaming input parameters and updating the `uses` directive. ```diff ```diff - uses: shivammathur/setup-php@v1 with: php-version: '7.4' - extension-csv: xml, pcov - ini-values-csv: post_max_size=256M - pecl: true + uses: shivammathur/setup-php@v2 with: php-version: '7.4' + extensions: xml, pcov + ini-values: post_max_size=256M + tools: pecl ``` ``` -------------------------------- ### Setup PHP with GitHub Token Authentication Source: https://github.com/shivammathur/setup-php/blob/main/README.md Configure the setup-php action to use a Personal Access Token (PAT) for GitHub authentication. This is useful for accessing private repositories. ```yaml - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.5' github-token: ${{ secrets.YOUR_PAT_TOKEN }} ``` -------------------------------- ### Setup PHP without Shared Extensions Except One Source: https://github.com/shivammathur/setup-php/blob/main/README.md Disables all shared extensions and then enables only 'mbstring'. Use 'none' to disable all core and third-party shared extensions. ```yaml - name: Setup PHP without any shared extensions except mbstring uses: shivammathur/setup-php@v2 with: php-version: '8.5' extensions: none, mbstring ``` -------------------------------- ### Setup Problem Matchers for PHP Source: https://github.com/shivammathur/setup-php/blob/main/README.md Add problem matchers for PHP output to highlight errors and warnings in the GitHub Actions UI. This step should be added after the setup-php step. ```yaml - name: Setup problem matchers for PHP run: echo "::add-matcher::${{ runner.tool_cache }}/php.json" ``` -------------------------------- ### Setup PHP with Specific PECL Extension Version Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs a specific version (1.9.3) of the swoole extension from PECL for an older PHP version (5.4). Useful for compatibility with end-of-life PHP versions. ```yaml - name: Setup PHP with specific version of PECL extension uses: shivammathur/setup-php@v2 with: php-version: '5.4' extensions: swoole-1.9.3 ``` -------------------------------- ### Setup PHP with Specific ICU Version for intl Extension Source: https://github.com/shivammathur/setup-php/blob/main/README.md Installs the 'intl' extension with a specific ICU version (77.1) for PHP 8.5 on Ubuntu. Ensure the ICU version is compatible with your PHP version. ```yaml - name: Setup PHP with intl uses: shivammathur/setup-php@v2 with: php-version: '8.5' extensions: intl-77.1 ```