setup-php/README.md

1088 lines
50 KiB
Markdown
Raw Normal View History

<p align="center">
<a href="https://github.com/marketplace/actions/setup-php-action" target="_blank">
<img src="https://repository-images.githubusercontent.com/206578964/e0a18480-dc65-11e9-8dd3-b9ffbf5575fe" alt="Setup PHP in GitHub Actions" width="400">
</a>
</p>
<h1 align="center">Setup PHP in GitHub Actions</h1>
2019-09-06 07:18:51 +07:00
<p align="center">
2019-10-10 19:17:17 +07:00
<a href="https://github.com/shivammathur/setup-php" title="GitHub action to setup PHP"><img alt="GitHub Actions status" src="https://github.com/shivammathur/setup-php/workflows/Main%20workflow/badge.svg"></a>
2020-10-05 15:25:56 +07:00
<a href="https://codecov.io/gh/shivammathur/setup-php" title="Code coverage"><img alt="Codecov Code Coverage" src="https://img.shields.io/codecov/c/github/shivammathur/setup-php?logo=codecov"></a>
2023-09-23 04:59:31 +07:00
<a href="https://github.com/shivammathur/setup-php/blob/main/LICENSE" title="license"><img alt="LICENSE" src="https://img.shields.io/badge/license-MIT-428f7e.svg?logo=open%20source%20initiative&logoColor=white&labelColor=555555"></a>
2023-08-30 16:44:35 +07:00
<a href="#tada-php-support" title="PHP Versions Supported"><img alt="PHP Versions Supported" src="https://img.shields.io/badge/php-5.3%20to%208.4-777bb3.svg?logo=php&logoColor=white&labelColor=555555"></a>
2020-08-19 08:19:39 +07:00
</p>
2021-07-16 16:44:15 +07:00
<p align="center">
2020-08-19 08:19:39 +07:00
<a href="https://reddit.com/r/setup_php" title="setup-php reddit"><img alt="setup-php reddit" src="https://img.shields.io/badge/reddit-join-FF5700?logo=reddit&logoColor=FF5700&labelColor=555555"></a>
<a href="https://twitter.com/setup_php" title="setup-php twitter"><img alt="setup-php twitter" src="https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter&logoColor=1DA1F2&labelColor=555555"></a>
2021-07-16 16:44:15 +07:00
<a href="https://status.setup-php.com" title="setup-php status"><img alt="setup-php status" src="https://img.shields.io/badge/status-subscribe-28A745?logo=statuspage&logoColor=28A745&labelColor=555555"></a>
2019-09-06 07:18:51 +07:00
</p>
2022-02-02 13:56:25 +07:00
Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer in [GitHub Actions](https://github.com/features/actions "GitHub Actions"). This action gives you a cross-platform interface to set up the PHP environment you need to test your application. Refer to [Usage](#memo-usage "How to use this") section and [examples](#examples "Examples of use") to see how to use this.
2019-11-03 11:41:44 +07:00
## Contents
- [OS/Platform Support](#cloud-osplatform-support)
2020-06-09 08:34:47 +07:00
- [GitHub-Hosted Runners](#github-hosted-runners)
- [Self-Hosted Runners](#self-hosted-runners)
2022-02-02 13:56:25 +07:00
- [PHP Support](#tada-php-support)
2019-12-27 08:26:49 +07:00
- [PHP Extension Support](#heavy_plus_sign-php-extension-support)
- [Tools Support](#wrench-tools-support)
2020-06-09 08:34:47 +07:00
- [Coverage Support](#signal_strength-coverage-support)
2019-11-03 11:41:44 +07:00
- [Xdebug](#xdebug)
- [PCOV](#pcov)
2020-02-14 14:15:46 +07:00
- [Disable Coverage](#disable-coverage)
2019-11-03 11:41:44 +07:00
- [Usage](#memo-usage)
2020-02-14 14:15:46 +07:00
- [Inputs](#inputs)
2021-07-14 15:43:16 +07:00
- [Outputs](#outputs)
2020-10-19 18:36:48 +07:00
- [Flags](#flags)
2019-12-18 23:14:02 +07:00
- [Basic Setup](#basic-setup)
2022-02-02 13:56:25 +07:00
- [Matrix Setup](#matrix-setup)
2020-06-09 08:34:47 +07:00
- [Nightly Build Setup](#nightly-build-setup)
2022-10-24 05:04:36 +07:00
- [Debug Build Setup](#debug-build-setup)
2020-11-24 12:33:03 +07:00
- [Thread Safe Setup](#thread-safe-setup)
- [Force Update Setup](#force-update-setup)
2022-02-02 13:56:25 +07:00
- [Verbose Setup](#verbose-setup)
2020-11-24 12:33:03 +07:00
- [Multi-Arch Setup](#multi-arch-setup)
2020-05-08 07:03:25 +07:00
- [Self Hosted Setup](#self-hosted-setup)
- [Local Testing Setup](#local-testing-setup)
2020-11-24 12:33:03 +07:00
- [JIT Configuration](#jit-configuration)
2020-02-14 14:15:46 +07:00
- [Cache Extensions](#cache-extensions)
- [Cache Composer Dependencies](#cache-composer-dependencies)
- [GitHub Composer Authentication](#github-composer-authentication)
- [Private Packagist Authentication](#private-packagist-authentication)
- [Manual Composer Authentication](#manual-composer-authentication)
2021-08-23 13:14:27 +07:00
- [Inline PHP Scripts](#inline-php-scripts)
2019-12-19 04:08:12 +07:00
- [Problem Matchers](#problem-matchers)
2019-11-03 11:41:44 +07:00
- [Examples](#examples)
2020-07-04 01:45:28 +07:00
- [Versioning](#bookmark-versioning)
2019-11-03 11:41:44 +07:00
- [License](#scroll-license)
- [Contributions](#1-contributions)
2020-02-14 14:15:46 +07:00
- [Support This Project](#sparkling_heart-support-this-project)
2020-07-04 01:45:28 +07:00
- [Dependencies](#package-dependencies)
2019-11-03 11:41:44 +07:00
- [Further Reading](#bookmark_tabs-further-reading)
## :cloud: OS/Platform Support
2022-02-02 13:56:25 +07:00
Both `GitHub-hosted` and `self-hosted` runners are supported by `setup-php` on the following OS/Platforms.
2020-06-09 08:34:47 +07:00
### GitHub-Hosted Runners
| Virtual environment | YAML workflow label | Pre-installed PHP |
|---------------------|------------------------------------|------------------------|
| Ubuntu 22.04 | `ubuntu-latest` or `ubuntu-22.04` | `PHP 8.1` |
| Ubuntu 20.04 | `ubuntu-20.04` | `PHP 7.4` to `PHP 8.3` |
| Windows Server 2022 | `windows-latest` or `windows-2022` | `PHP 8.2` |
| Windows Server 2019 | `windows-2019` | `PHP 8.2` |
| macOS Sonoma 14.x | `macos-14` | - |
| macOS Ventura 13.x | `macos-13` | `PHP 8.3` |
| macOS Monterey 12.x | `macos-latest` or `macos-12` | `PHP 8.3` |
2020-06-09 08:34:47 +07:00
### Self-Hosted Runners
2022-02-02 13:56:25 +07:00
| Host OS/Virtual environment | YAML workflow label |
|----------------------------------|----------------------------|
| Ubuntu 22.04 | `self-hosted` or `Linux` |
2022-02-02 13:56:25 +07:00
| Ubuntu 20.04 | `self-hosted` or `Linux` |
| Debian 11 | `self-hosted` or `Linux` |
| Debian 10 | `self-hosted` or `Linux` |
| Windows 7 and newer | `self-hosted` or `Windows` |
| Windows Server 2012 R2 and newer | `self-hosted` or `Windows` |
| macOS Sonoma 14.x x86_64/arm64 | `self-hosted` or `macOS` |
| macOS Ventura 13.x x86_64/arm64 | `self-hosted` or `macOS` |
2022-02-02 13:56:25 +07:00
| macOS Monterey 12.x x86_64/arm64 | `self-hosted` or `macOS` |
2020-05-08 07:03:25 +07:00
2020-06-09 08:34:47 +07:00
- Refer to the [self-hosted setup](#self-hosted-setup) to use the action on self-hosted runners.
2022-02-02 13:56:25 +07:00
- Operating systems based on the above Ubuntu and Debian versions are also supported on best effort basis.
2020-12-14 15:28:47 +07:00
- If the requested PHP version is pre-installed, `setup-php` switches to it, otherwise it installs the PHP version.
## :tada: PHP Support
On all supported OS/Platforms the following PHP versions can be set up as per the runner.
2020-12-14 15:28:47 +07:00
2023-08-30 16:44:35 +07:00
- PHP 5.3 to PHP 8.4 on GitHub-hosted runners.
- PHP 5.6 to PHP 8.4 on self-hosted runners.
2020-12-14 15:28:47 +07:00
2022-02-02 13:56:25 +07:00
| PHP Version | Stability | Release Support | Runner Support |
|-------------|-----------|-----------------------|--------------------------------|
| `5.3` | `Stable` | `End of life` | `GitHub-hosted` |
| `5.4` | `Stable` | `End of life` | `GitHub-hosted` |
| `5.5` | `Stable` | `End of life` | `GitHub-hosted` |
| `5.6` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
| `7.0` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
| `7.1` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
| `7.2` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
| `7.3` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
| `7.4` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
2023-11-23 18:42:56 +07:00
| `8.0` | `Stable` | `End of life` | `GitHub-hosted`, `self-hosted` |
| `8.1` | `Stable` | `Security fixes only` | `GitHub-hosted`, `self-hosted` |
| `8.2` | `Stable` | `Active` | `GitHub-hosted`, `self-hosted` |
| `8.3` | `Stable` | `Active` | `GitHub-hosted`, `self-hosted` |
2023-08-30 16:44:35 +07:00
| `8.4` | `Nightly` | `In development` | `GitHub-hosted`, `self-hosted` |
2022-02-02 13:56:25 +07:00
**Notes:**
2023-11-23 18:42:56 +07:00
- Specifying `8.4` in `php-version` input installs a nightly build of `PHP 8.4.0-dev`. See [nightly build setup](#nightly-build-setup) for more information.
2021-09-01 21:04:48 +07:00
- To use JIT on `PHP 8.0` and above, refer to the [JIT configuration](#jit-configuration) section.
2019-12-27 08:26:49 +07:00
## :heavy_plus_sign: PHP Extension Support
2020-05-08 07:03:25 +07:00
2021-08-23 13:14:27 +07:00
PHP extensions can be set up using the `extensions` input. It accepts a `string` in csv-format.
2020-11-16 02:52:24 +07:00
- On `Ubuntu`, extensions which are available as a package, available on `PECL` or a git repository can be set up.
2020-02-14 14:15:46 +07:00
```yaml
2020-12-17 13:43:39 +07:00
- name: Setup PHP with PECL extension
2020-08-19 08:19:39 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-12-14 15:28:47 +07:00
extensions: imagick, swoole
2020-02-14 14:15:46 +07:00
```
- On `Windows`, extensions available on `PECL` which have the `DLL` binary can be set up.
2020-02-14 14:15:46 +07:00
- On `macOS`, extensions available on `PECL` or a git repository can be set up.
- On `Ubuntu` and `macOS` to compile and install an extension from a git repository follow this [guide](https://github.com/shivammathur/setup-php/wiki/Add-extension-from-source "Guide to compile and install PHP extensions in setup-php").
2020-02-14 14:15:46 +07:00
2020-02-29 22:38:26 +07:00
- Extensions installed along with PHP if specified are enabled.
2020-02-14 14:15:46 +07:00
2021-08-23 13:14:27 +07:00
- Specific versions of extensions available on `PECL` can be set up by suffixing the extension's name with the version. This is useful for installing old versions of extensions which support end of life PHP versions.
2020-02-14 14:15:46 +07:00
```yaml
2020-08-19 08:19:39 +07:00
- name: Setup PHP with specific version of PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '5.4'
extensions: swoole-1.9.3
2020-02-14 14:15:46 +07:00
```
2022-02-02 13:56:25 +07:00
- Extensions with pre-release versions available on `PECL` can be set up by suffixing the extension's name with its state i.e `alpha`, `beta`, `devel` or `snapshot`.
2020-02-14 14:15:46 +07:00
```yaml
2020-08-19 08:19:39 +07:00
- name: Setup PHP with pre-release PECL extension
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-08-19 08:19:39 +07:00
extensions: xdebug-beta
2020-02-14 14:15:46 +07:00
```
2022-03-22 20:50:39 +07:00
- On `Ubuntu` and `macOS` to compile and install an extension from PECL with libraries or custom configuration follow this [guide](https://github.com/shivammathur/setup-php/wiki/Add-extension-from-PECL-with-libraries-and-custom-configuration "Guide to compile and install PHP extensions using PECL with libraries and custom configuration in setup-php").
- Shared extensions can be disabled by prefixing them with a `:`. All extensions depending on the specified extension will also be disabled.
2020-05-08 07:03:25 +07:00
```yaml
- name: Setup PHP and disable opcache
2020-08-19 08:19:39 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-08-19 08:19:39 +07:00
extensions: :opcache
```
- All shared extensions can be disabled by specifying `none`. When `none` is specified along with other extensions, it is hoisted to the start of the input. So, all the shared extensions will be disabled first, then rest of the extensions in the input will be processed.
2022-02-02 13:56:25 +07:00
**Note:** This disables all core and third-party shared extensions and thus, can break some tools which need them. Required extensions are enabled again when the tools are set up on a best-effort basis. So it is recommended to add the extensions required for your tools after `none` in the `extensions` input to avoid any issues.
```yaml
- name: Setup PHP without any shared extensions except mbstring
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
extensions: none, mbstring
```
2021-08-23 13:14:27 +07:00
- Extension `intl` can be set up with specific `ICU` version for `PHP 5.6` and above in `Ubuntu` workflows by suffixing `intl` with the `ICU` version. `ICU 50.2` and newer versions are supported. Refer to [`ICU builds`](https://github.com/shivammathur/icu-intl#icu4c-builds) for the specific versions supported.
2020-08-19 08:19:39 +07:00
```yaml
- name: Setup PHP with intl
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2022-02-02 13:56:25 +07:00
extensions: intl-70.1
2020-05-08 07:03:25 +07:00
```
2020-12-14 15:28:47 +07:00
- Extensions loaded by default after `setup-php` runs can be found on the [wiki](https://github.com/shivammathur/setup-php/wiki).
2020-12-14 14:22:00 +07:00
- These extensions have custom support:
2022-11-14 16:47:12 +07:00
- `cubrid` and `pdo_cubrid` on `Ubuntu`.
2023-01-12 17:44:06 +07:00
- `event`, `gearman`, `geos` and `relay` on `Ubuntu` and `macOS`.
2023-01-22 03:34:12 +07:00
- `blackfire`, `couchbase`, `ioncube`, `oci8`, `pdo_firebird`, `pdo_oci`, `pecl_http`, `phalcon3`, `phalcon4`, `phalcon5`, and `zephir_parser` on all supported OS.
2019-09-07 19:31:50 +07:00
2022-02-02 13:56:25 +07:00
- By default, extensions which cannot be added or disabled gracefully leave an error message in the logs, the execution is not interrupted. To change this behaviour you can set `fail-fast` flag to `true`.
2020-10-19 18:36:48 +07:00
```yaml
- name: Setup PHP with fail-fast
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-10-19 18:36:48 +07:00
extensions: oci8
env:
fail-fast: true
```
2019-12-27 08:26:49 +07:00
## :wrench: Tools Support
2021-08-23 13:14:27 +07:00
These tools can be set up globally using the `tools` input. It accepts a string in csv-format.
2019-12-27 08:26:49 +07:00
[`behat`], [`blackfire`], [`blackfire-player`], [`box`], [`castor`], [`churn`], [`codeception`], [`composer`], [`composer-normalize`], [`composer-prefetcher`], [`composer-require-checker`], [`composer-unused`], [`cs2pr`], [`deployer`], [`flex`], [`grpc_php_plugin`], [`infection`], [`parallel-lint`], [`pecl`], [`phan`], [`phing`], [`phinx`], [`phive`], [`php-config`], [`php-cs-fixer`], [`php-scoper`], [`phpcbf`], [`phpcpd`], [`phpcs`], [`phpdoc`] or [`phpDocumentor`], [`phpize`], [`phplint`], [`phpmd`], [`phpspec`], [`phpstan`], [`phpunit`], [`phpunit-bridge`], [`phpunit-polyfills`], [`pint`], [`prestissimo`], [`protoc`], [`psalm`], [`rector`], [`symfony`] or [`symfony-cli`], [`vapor`] or [`vapor-cli`], [`wp`] or [`wp-cli`]
2019-12-27 08:26:49 +07:00
```yaml
2020-08-19 08:19:39 +07:00
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-08-19 08:19:39 +07:00
tools: php-cs-fixer, phpunit
2019-12-27 08:26:49 +07:00
```
2021-07-14 15:43:16 +07:00
- In addition to above tools any composer tool or package can also be set up globally by specifying it as `vendor/package` matching the listing on Packagist. This format accepts the same [version constraints](https://getcomposer.org/doc/articles/versions.md#writing-version-constraints "Composer version constraints") as `composer`.
2020-06-09 08:34:47 +07:00
```yaml
2021-07-14 15:43:16 +07:00
- name: Setup PHP with tools
2020-08-19 08:19:39 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-07-14 15:43:16 +07:00
tools: vimeo/psalm
2020-06-09 08:34:47 +07:00
```
2021-07-14 15:43:16 +07:00
- To set up a particular version of a tool, specify it in the form `tool:version`.
Version can be in the following format:
- Semver. For example `tool:1.2.3` or `tool:1.2.3-beta1`.
- Major version. For example `tool:1` or `tool:1.x`.
- Major and minor version. For example `tool:1.2` or `tool:1.2.x`.
When you specify just the major version or the version in `major.minor` format, the latest patch version matching the input will be setup.
With the exception of major versions of `composer`, if you specify only the `major` version or the version in `major.minor` format for a tool you can get rate limited by GitHub's API. To avoid this, it is recommended to provide a [`GitHub` OAuth token](https://github.com/shivammathur/setup-php#composer-github-oauth "Composer GitHub OAuth").
2022-07-19 17:14:51 +07:00
You can do that by setting `GITHUB_TOKEN` environment variable. The `COMPOSER_TOKEN` environment variable has been deprecated in favor of `GITHUB_TOKEN` and will be removed in the next major version.
2021-04-26 11:38:04 +07:00
```yaml
2021-07-14 15:43:16 +07:00
- name: Setup PHP with tools
2021-04-26 11:38:04 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
tools: php-cs-fixer:3.39, phpunit:10.4
2021-07-14 15:43:16 +07:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2021-04-26 11:38:04 +07:00
```
- The latest stable version of `composer` is set up by default. You can set up the required `composer` version by specifying the major version `v1` or `v2`, or the version in `major.minor` or `semver` format. Additionally, for composer `snapshot` and `preview` can also be specified to set up the respective releases.
```yaml
2021-07-14 15:43:16 +07:00
- name: Setup PHP with composer v2
2020-08-19 08:19:39 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-07-14 15:43:16 +07:00
tools: composer:v2
2020-06-09 08:34:47 +07:00
```
2021-07-14 15:43:16 +07:00
- If you do not use composer in your workflow, you can specify `tools: none` to skip it.
2021-04-26 11:38:04 +07:00
```yaml
2021-07-14 15:43:16 +07:00
- name: Setup PHP without composer
2021-04-26 11:38:04 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-07-14 15:43:16 +07:00
tools: none
2021-04-26 11:38:04 +07:00
```
2022-02-02 13:56:25 +07:00
- Tools `pear`, `pecl`, `phpize` and `php-config` are set up by default for all supported PHP versions on Linux and macOS.
2021-07-14 15:43:16 +07:00
2021-08-23 13:14:27 +07:00
- The latest version of `blackfire` cli is set up when `blackfire` is specified in tools input. Please refer to the [official documentation](https://blackfire.io/docs/integrations/ci/github-actions "Blackfire.io documentation for GitHub Actions") for using `blackfire` with GitHub Actions.
2021-07-14 15:43:16 +07:00
- Tools `prestissimo` and `composer-prefetcher` will be skipped unless `composer:v1` is also specified in tools input. It is recommended to drop `prestissimo` and use `composer v2`.
2023-02-03 17:02:03 +07:00
- By default, except `composer` tools which cannot be set up gracefully leave an error message in the logs, the execution is not interrupted. To change this behaviour you can set `fail-fast` flag to `true`.
2020-10-19 18:36:48 +07:00
```yaml
- name: Setup PHP with fail-fast
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-10-19 18:36:48 +07:00
tools: deployer
env:
fail-fast: true
```
2020-02-29 22:38:26 +07:00
**Notes**
2022-02-02 13:56:25 +07:00
- Input `tools` is useful to set up tools which are only used in CI workflows, thus keeping your `composer.json` tidy.
- If you do not want to use all your dev-dependencies in workflow, you can run composer with `--no-dev` and install required tools using `tools` input to speed up your workflow.
- By default, `COMPOSER_NO_INTERACTION` is set to `1` and `COMPOSER_PROCESS_TIMEOUT` is set to `0`. In effect, this means that Composer commands in your scripts do not need to specify `--no-interaction`.
- Also, `COMPOSER_NO_AUDIT` is set to `1`. So if you want to audit your dependencies for security vulnerabilities, it is recommended to add a `composer audit` step before you install them.
- If you want to set a different `COMPOSER_PROCESS_TIMEOUT`, you can set it in your workflow file using the `env` keyword.
```yaml
- name: Setup PHP with composer and custom process timeout
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
env:
COMPOSER_PROCESS_TIMEOUT: 300
```
2019-12-28 01:53:51 +07:00
2020-06-09 08:34:47 +07:00
## :signal_strength: Coverage Support
2019-10-05 16:30:00 +07:00
### Xdebug
2021-04-26 11:38:04 +07:00
Specify `coverage: xdebug` to use `Xdebug` and disable `PCOV`.
2020-06-19 05:39:13 +07:00
Runs on all [PHP versions supported](#tada-php-support "List of PHP versions supported on this GitHub Action").
2019-10-08 19:42:54 +07:00
```yaml
2020-08-19 08:19:39 +07:00
- name: Setup PHP with Xdebug
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-08-19 08:19:39 +07:00
coverage: xdebug
```
2019-10-05 16:30:00 +07:00
2021-12-19 18:39:41 +07:00
- When you specify `coverage: xdebug`, the latest version of Xdebug compatible with the PHP version is set up by default.
2021-02-02 08:52:26 +07:00
- If you need Xdebug 2.x on PHP 7.2, 7.3 or 7.4, you can specify `coverage: xdebug2`.
```yaml
- name: Setup PHP with Xdebug 2.x
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: xdebug2
```
2021-12-19 18:39:41 +07:00
**Note**: Xdebug is enabled by default on Ubuntu GitHub Actions images, so if you are not using it in your workflow it is recommended to disable it as that will have a positive impact on your PHP performance. Please refer to the [disable coverage](#disable-coverage) section for details.
2019-10-05 16:30:00 +07:00
### PCOV
2021-04-26 11:38:04 +07:00
Specify `coverage: pcov` to use `PCOV` and disable `Xdebug`.
2021-02-02 08:52:26 +07:00
Runs on PHP 7.1 and newer PHP versions.
2021-04-26 11:38:04 +07:00
2021-02-02 08:52:26 +07:00
- If your source code directory is other than `src`, `lib` or, `app`, specify `pcov.directory` using the `ini-values` input.
2019-10-13 11:18:29 +07:00
2019-10-08 19:42:54 +07:00
```yaml
2020-08-19 08:19:39 +07:00
- name: Setup PHP with PCOV
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-08-19 08:19:39 +07:00
ini-values: pcov.directory=api #optional, see above for usage.
coverage: pcov
```
2021-02-02 08:52:26 +07:00
- PHPUnit 8.x and above supports PCOV out of the box.
- If you are using PHPUnit 5.x, 6.x or 7.x, you need to set up `pcov/clobber` before executing your tests.
2020-08-19 08:19:39 +07:00
```yaml
- name: Setup PCOV
run: |
composer require pcov/clobber
vendor/bin/pcov clobber
```
2020-02-14 14:15:46 +07:00
### Disable Coverage
2019-10-10 19:17:17 +07:00
Specify `coverage: none` to disable both `Xdebug` and `PCOV`.
2021-02-22 09:31:32 +07:00
Disable coverage for these reasons:
2019-11-03 11:41:44 +07:00
2019-10-10 19:17:17 +07:00
- You are not generating coverage reports while testing.
2019-11-03 11:41:44 +07:00
- You are using `phpdbg` for running your tests.
2020-02-29 22:38:26 +07:00
- You are profiling your code using `blackfire`.
2021-04-26 11:38:04 +07:00
- You are using PHP in JIT mode. Please refer to [JIT configuration](#jit-configuration) section for more details.
2019-10-08 19:42:54 +07:00
```yaml
2020-08-19 08:19:39 +07:00
- name: Setup PHP with no coverage driver
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-08-19 08:19:39 +07:00
coverage: none
2019-10-05 16:30:00 +07:00
```
## :memo: Usage
2019-09-06 07:18:51 +07:00
2020-02-14 14:15:46 +07:00
### Inputs
2020-10-19 18:36:48 +07:00
> Specify using `with` keyword
2023-01-29 12:26:49 +07:00
#### `php-version` (optional)
2020-02-14 14:15:46 +07:00
2020-10-19 18:36:48 +07:00
- Specify the PHP version you want to set up.
- Accepts a `string`. For example `'8.3'`.
2023-12-08 05:02:03 +07:00
- Accepts `lowest` to set up the lowest supported PHP version.
- Accepts `highest` or `latest` to set up the latest stable PHP version.
2021-09-06 13:28:31 +07:00
- Accepts `nightly` to set up a nightly build from the master branch of PHP.
2021-02-02 08:52:26 +07:00
- Accepts the format `d.x`, where `d` is the major version. For example `5.x`, `7.x` and `8.x`.
- See [PHP support](#tada-php-support) for the supported PHP versions.
- If not specified, it looks for the following in order:
- The `php-version-file` input if it exists
- A `composer.lock` file and the `platform-overrides.php` value
- A `composer.json` file and the `config.platform.php` value
2023-01-29 12:26:49 +07:00
#### `php-version-file` (optional)
- Specify a file with the PHP version you want to set up.
2023-01-29 12:26:49 +07:00
- Accepts a `string`. For example `'.phpenv-version'`.
- See [PHP support](#tada-php-support) for the supported PHP versions.
2023-01-29 12:26:49 +07:00
- By default, `.php-version` file is used.
- If not specified and the default `.php-version` file is not found, the latest stable PHP version is set up.
2020-02-14 14:15:46 +07:00
#### `extensions` (optional)
- Specify the extensions you want to add or disable.
2020-05-08 07:03:25 +07:00
- Accepts a `string` in csv-format. For example `mbstring, :opcache`.
- Accepts `none` to disable all shared extensions.
- Shared extensions prefixed with `:` are disabled.
2020-02-14 14:15:46 +07:00
- See [PHP extension support](#heavy_plus_sign-php-extension-support) for more info.
2019-09-06 07:18:51 +07:00
2022-01-25 15:13:49 +07:00
#### `ini-file` (optional)
- Specify the base `php.ini` file.
- Accepts `production`, `development` or `none`.
- By default, production `php.ini` file is used.
2020-02-14 14:15:46 +07:00
#### `ini-values` (optional)
2020-11-24 12:33:03 +07:00
- Specify the values you want to add to `php.ini`.
2021-02-02 08:52:26 +07:00
- Accepts a `string` in csv-format. For example `post_max_size=256M, max_execution_time=180`.
- Accepts ini values with commas if wrapped in quotes. For example `xdebug.mode="develop,coverage"`.
2020-02-14 14:15:46 +07:00
#### `coverage` (optional)
- Specify the code-coverage driver you want to set up.
2020-02-14 14:15:46 +07:00
- Accepts `xdebug`, `pcov` or `none`.
- See [coverage support](#signal_strength-coverage-support) for more info.
#### `tools` (optional)
2020-10-19 18:36:48 +07:00
- Specify the tools you want to set up.
- Accepts a `string` in csv-format. For example: `phpunit, phpcs`
2022-06-21 14:39:42 +07:00
- See [tools support](#wrench-tools-support) for tools supported.
2020-02-14 14:15:46 +07:00
2021-07-14 15:43:16 +07:00
### Outputs
#### `php-version`
2022-02-02 13:56:25 +07:00
On GitHub Actions you can assign the `setup-php` step an `id`, you can use the same to get the outputs in a later step.
2021-07-14 15:43:16 +07:00
- Provides the PHP version in semver format.
2021-08-23 13:14:27 +07:00
```yaml
2021-07-14 15:43:16 +07:00
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-07-14 15:43:16 +07:00
- name: Print PHP version
run: echo ${{ steps.setup-php.outputs.php-version }}
```
2020-10-19 18:36:48 +07:00
### Flags
> Specify using `env` keyword
#### `fail-fast` (optional)
- Specify to mark the workflow as failed if an extension or tool fails to set up.
- This changes the default mode from graceful warnings to fail-fast.
- By default, it is set to `false`.
- Accepts `true` and `false`.
#### `phpts` (optional)
2023-12-25 04:39:27 +07:00
- Specify to set up a thread-safe build of PHP.
2023-11-27 19:37:02 +07:00
- Accepts `nts` for non-thread-safe and `zts` or `ts` for thread-safe.
2020-10-19 18:36:48 +07:00
- By default, it is set to `nts`.
- See [thread safe setup](#thread-safe-setup) for more info.
#### `update` (optional)
- Specify to update PHP on the runner to the latest patch version.
- Accepts `true` and `false`.
- By default, it is set to `false`.
2020-11-24 12:33:03 +07:00
- See [force update setup](#force-update-setup) for more info.
2020-10-19 18:36:48 +07:00
2020-02-14 14:15:46 +07:00
See below for more info.
### Basic Setup
2019-12-09 14:10:12 +07:00
2022-02-02 13:56:25 +07:00
> Set up a particular PHP version.
2019-09-06 07:18:51 +07:00
```yaml
steps:
2019-10-19 21:29:48 +07:00
- name: Setup PHP
2020-02-14 14:15:46 +07:00
uses: shivammathur/setup-php@v2
2019-09-06 07:18:51 +07:00
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-02-14 14:15:46 +07:00
extensions: mbstring, intl
2020-11-24 12:33:03 +07:00
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
2020-02-14 14:15:46 +07:00
tools: php-cs-fixer, phpunit
2019-09-06 07:18:51 +07:00
```
2019-12-18 23:14:02 +07:00
### Matrix Setup
2019-12-09 14:10:12 +07:00
2022-02-02 13:56:25 +07:00
> Set up multiple PHP versions on multiple operating systems.
2019-09-06 07:18:51 +07:00
```yaml
jobs:
run:
2019-09-06 07:18:51 +07:00
runs-on: ${{ matrix.operating-system }}
strategy:
2019-09-06 07:18:51 +07:00
matrix:
2020-12-14 15:28:47 +07:00
operating-system: ['ubuntu-latest', 'windows-latest', 'macos-latest']
2023-02-03 17:02:03 +07:00
php-versions: ['8.1', '8.2', '8.3']
2020-12-14 15:28:47 +07:00
phpunit-versions: ['latest']
include:
2023-02-03 17:02:03 +07:00
- operating-system: 'ubuntu-latest'
php-versions: '8.0'
phpunit-versions: 9
2019-09-06 07:18:51 +07:00
steps:
2019-10-19 21:29:48 +07:00
- name: Setup PHP
2020-02-14 14:15:46 +07:00
uses: shivammathur/setup-php@v2
2019-09-06 07:18:51 +07:00
with:
2019-11-07 16:32:05 +07:00
php-version: ${{ matrix.php-versions }}
2020-02-14 14:15:46 +07:00
extensions: mbstring, intl
2020-11-24 12:33:03 +07:00
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
2020-12-14 15:28:47 +07:00
tools: php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}
2023-02-03 17:02:03 +07:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2019-09-06 07:18:51 +07:00
```
2020-11-24 12:33:03 +07:00
### Nightly Build Setup
2023-11-23 18:42:56 +07:00
> Set up a nightly build of `PHP 8.4`.
2020-11-24 12:33:03 +07:00
2023-08-30 16:44:35 +07:00
- These PHP versions are currently in active development and might contain bugs and breaking changes.
2020-11-24 12:33:03 +07:00
- Some user space extensions might not support this version currently.
```yaml
steps:
- name: Setup nightly PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.4'
2020-11-24 12:33:03 +07:00
extensions: mbstring
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: php-cs-fixer, phpunit
```
2022-10-24 05:04:36 +07:00
### Debug Build Setup
> Set up a PHP build with debugging symbols.
- Production release builds of PHP without debugging symbols are set up by default.
- You can use the `debug` environment variable to set up a build with debugging symbols for PHP 5.6 and above.
**Notes**
- On Linux, the debug symbols are added as [debug info files](https://sourceware.org/gdb/current/onlinedocs/gdb.html/Separate-Debug-Files.html) in the `/usr/lib/debug/.build-id` directory. These files match the `build-id` in the ELF section of the PHP binaries and debugging tools like `gdb` are able to resolve the symbols from these files.
- On Windows, the debug symbols are added as `pdb` files in the PHP installation directory.
- On macOS, the debug symbols are compiled into the binaries.
2022-10-24 05:04:36 +07:00
```yaml
steps:
- name: Setup PHP with debugging symbols
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2022-10-24 05:04:36 +07:00
env:
debug: true # specify true or false
```
2020-11-24 12:33:03 +07:00
### Thread Safe Setup
2023-12-25 04:39:27 +07:00
> Set up `TS` or `NTS` PHP.
2020-11-24 12:33:03 +07:00
2021-08-23 13:14:27 +07:00
- `NTS` versions are set up by default.
2020-11-24 12:33:03 +07:00
```yaml
jobs:
run:
2023-12-25 04:39:27 +07:00
runs-on: [ubuntu-latest, windows-latest, macos-latest]
2022-12-26 05:15:00 +07:00
name: Setup PHP TS
2020-11-24 12:33:03 +07:00
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-11-24 12:33:03 +07:00
env:
phpts: ts # specify ts or nts
```
### Force Update Setup
> Update to the latest patch of PHP versions.
2022-02-02 13:56:25 +07:00
- Pre-installed PHP versions are not updated to their latest patch release by default.
- If `ppa:ondrej/php` is missing on the Ubuntu GitHub environment, the PHP version is updated to the latest patch release.
2021-02-22 09:31:32 +07:00
- You can specify the `update` environment variable to `true` for updating to the latest release.
2020-11-24 12:33:03 +07:00
```yaml
- name: Setup PHP with latest versions
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-11-24 12:33:03 +07:00
env:
update: true # specify true or false
```
### Verbose Setup
> Debug your workflow
To debug any issues, you can use the `verbose` tag instead of `v2`.
```yaml
- name: Setup PHP with logs
uses: shivammathur/setup-php@verbose
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-11-24 12:33:03 +07:00
```
2020-11-16 02:52:24 +07:00
### Multi-Arch Setup
2022-02-02 13:56:25 +07:00
> Set up PHP on multiple architecture on Ubuntu GitHub Runners.
2020-11-16 02:52:24 +07:00
2023-11-23 18:42:56 +07:00
- `PHP 5.6` to `PHP 8.3` are supported by `setup-php` on multiple architecture on `Ubuntu`.
2022-02-02 13:56:25 +07:00
- For this, you can use `shivammathur/node` images as containers. These have compatible `Nodejs` installed for `setup-php`.
2021-08-23 13:14:27 +07:00
- Currently, for `ARM` based setup, you will need [self-hosted runners](#self-hosted-setup).
2020-11-16 02:52:24 +07:00
```yaml
jobs:
run:
runs-on: ubuntu-latest
container: shivammathur/node:latest-${{ matrix.arch }}
strategy:
matrix:
arch: ["amd64", "i386"]
steps:
- name: Install PHP
2021-08-23 13:14:27 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-11-16 02:52:24 +07:00
```
2020-05-08 07:03:25 +07:00
### Self Hosted Setup
2022-02-02 13:56:25 +07:00
> Set up PHP on a self-hosted runner.
2020-05-08 07:03:25 +07:00
2021-08-23 13:14:27 +07:00
- To set up a containerised self-hosted runner, refer to the following guides as per your base operating system.
- [Linux](https://github.com/shivammathur/setup-php/wiki/Dockerized-self-hosted-runner-on-Linux)
- [Windows](https://github.com/shivammathur/setup-php/wiki/Dockerized-self-hosted-runner-on-Windows)
2020-10-19 18:36:48 +07:00
- To set up the runner directly on the host OS or in a virtual machine, follow this [requirements guide](https://github.com/shivammathur/setup-php/wiki/Requirements-for-self-hosted-runners "Requirements guide for self-hosted runner to run setup-php") before setting up the self-hosted runner.
2021-08-23 13:14:27 +07:00
- If your workflow uses [service containers](https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idservices "GitHub Actions Services"), then set up the runner on a Linux host or in a Linux virtual machine. GitHub Actions does not support nested virtualization on Linux, so services will not work in a dockerized container.
2020-05-08 07:03:25 +07:00
2022-02-02 13:56:25 +07:00
It is recommended to specify the environment variable `runner` with the value `self-hosted` for self-hosted environments.
2020-05-08 07:03:25 +07:00
```yaml
jobs:
run:
runs-on: self-hosted
strategy:
matrix:
2023-11-23 18:42:56 +07:00
php-versions: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
2020-05-08 07:03:25 +07:00
name: PHP ${{ matrix.php-versions }}
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
env:
2022-02-02 13:56:25 +07:00
runner: self-hosted
2020-05-08 07:03:25 +07:00
```
2020-08-13 01:21:33 +07:00
**Notes**
2021-02-22 09:31:32 +07:00
- Do not set up multiple self-hosted runners on a single server instance as parallel workflow will conflict with each other.
- Do not set up self-hosted runners on the side on your development environment or your production server.
2020-11-16 02:52:24 +07:00
- Avoid using the same labels for your `self-hosted` runners which are used by `GitHub-hosted` runners.
2020-08-13 01:21:33 +07:00
2020-05-08 07:03:25 +07:00
### Local Testing Setup
> Test your `Ubuntu` workflow locally using [`nektos/act`](https://github.com/nektos/act "Project to test GitHub Actions locally").
```yaml
jobs:
run:
runs-on: ubuntu-latest
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2020-05-08 07:03:25 +07:00
```
2020-12-14 15:28:47 +07:00
Run the workflow locally with `act` using [`shivammathur/node`](https://github.com/shivammathur/node-docker "Docker image to run setup-php") docker images.
2020-05-08 07:03:25 +07:00
Choose the image tag which matches the `runs-on` property in your workflow. For example, if you are using `ubuntu-20.04` in your workflow, run `act -P ubuntu-20.04=shivammathur/node:2004`.
2021-02-22 09:31:32 +07:00
2020-05-08 07:03:25 +07:00
```bash
# For runs-on: ubuntu-latest
act -P ubuntu-latest=shivammathur/node:latest
2022-05-06 07:13:20 +07:00
# For runs-on: ubuntu-22.04
act -P ubuntu-22.04=shivammathur/node:2204
2020-06-09 08:34:47 +07:00
# For runs-on: ubuntu-20.04
act -P ubuntu-20.04=shivammathur/node:2004
2020-05-08 07:03:25 +07:00
```
2020-11-24 12:33:03 +07:00
### JIT Configuration
2020-01-21 09:31:10 +07:00
2022-06-21 14:39:42 +07:00
> Enable Just-in-time (JIT) on PHP 8.0 and above.
2020-05-08 07:03:25 +07:00
2020-11-24 12:33:03 +07:00
- To enable JIT, enable `opcache` in cli mode by setting `opcache.enable_cli=1`.
- JIT conflicts with `Xdebug`, `PCOV`, and other extensions which override `zend_execute_ex` function, so set `coverage: none` and disable any such extension if added.
2020-11-24 12:33:03 +07:00
- By default, `opcache.jit=1235` and `opcache.jit_buffer_size=256M` are set which can be changed using `ini-values` input.
2022-06-21 15:04:28 +07:00
- For detailed information about JIT related directives refer to the [`official PHP documentation`](https://www.php.net/manual/en/opcache.configuration.php#ini.opcache.jit "opcache.jit documentation").
2020-01-21 09:31:10 +07:00
2020-11-24 12:33:03 +07:00
For example to enable JIT in `tracing` mode with buffer size of `64 MB`.
2020-02-14 14:15:46 +07:00
```yaml
2020-11-24 12:33:03 +07:00
- name: Setup PHP with JIT in tracing mode
2020-02-14 14:15:46 +07:00
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-04-26 11:38:04 +07:00
coverage: none
2020-11-24 12:33:03 +07:00
ini-values: opcache.enable_cli=1, opcache.jit=tracing, opcache.jit_buffer_size=64M
2020-02-14 14:15:46 +07:00
```
### Cache Extensions
2020-10-19 18:36:48 +07:00
You can cache PHP extensions using `shivammathur/cache-extensions` and `action/cache` GitHub Actions. Extensions which take very long to set up when cached are available in the next workflow run and are enabled directly. This reduces the workflow execution time.
Refer to [`shivammathur/cache-extensions`](https://github.com/shivammathur/cache-extensions "GitHub Action to cache php extensions") for details.
2020-02-29 22:38:26 +07:00
2020-02-14 14:15:46 +07:00
### Cache Composer Dependencies
2019-11-03 11:41:44 +07:00
2020-10-19 18:36:48 +07:00
If your project uses composer, you can persist the composer's internal cache directory. Dependencies cached are loaded directly instead of downloading them while installation. The files cached are available across check-runs and will reduce the workflow execution time.
2019-11-05 06:28:15 +07:00
2019-11-03 11:41:44 +07:00
```yaml
2020-02-21 15:09:04 +07:00
- name: Get composer cache directory
id: composer-cache
2022-10-12 17:56:11 +07:00
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
2019-11-08 17:26:57 +07:00
- name: Cache dependencies
uses: actions/cache@v4
2019-11-05 06:28:15 +07:00
with:
path: ${{ steps.composer-cache.outputs.dir }}
2019-11-05 06:28:15 +07:00
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
2019-11-08 17:26:57 +07:00
2020-02-21 15:09:04 +07:00
- name: Install dependencies
2019-11-05 06:28:15 +07:00
run: composer install --prefer-dist
2019-11-03 11:41:44 +07:00
```
2020-02-29 22:38:26 +07:00
**Notes**
2020-10-19 18:36:48 +07:00
- Please do not cache `vendor` directory using `action/cache` as that will have side effects.
2020-11-16 02:52:24 +07:00
- If you do not commit `composer.lock`, you can use the hash of `composer.json` as the key for your cache.
```yaml
2020-02-21 15:09:04 +07:00
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
```
2020-11-16 02:52:24 +07:00
- If you support a range of `composer` dependencies and use `prefer-lowest` and `prefer-stable` options, you can store them in your matrix and add them to the keys.
```yaml
key: ${{ runner.os }}-composer-${{ matrix.prefer }}-${{ hashFiles('**/composer.lock') }}
2020-11-16 02:52:24 +07:00
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-
```
### GitHub Composer Authentication
2020-02-21 15:09:04 +07:00
If you have a number of workflows which set up multiple tools or have many composer dependencies, you might hit the GitHub's rate limit for composer. Also, if you specify only the major version or the version in `major.minor` format, you can hit the rate limit. To avoid this you can specify an `OAuth` token by setting `GITHUB_TOKEN` environment variable. You can use [`GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token "GITHUB_TOKEN documentation") secret for this purpose.
2022-07-19 17:14:51 +07:00
The `COMPOSER_TOKEN` environment variable has been deprecated in favor of `GITHUB_TOKEN` and will be removed in the next major version.
2020-02-21 15:09:04 +07:00
```yaml
2021-08-23 13:14:27 +07:00
- name: Setup PHP
uses: shivammathur/setup-php@v2
2020-02-21 15:09:04 +07:00
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-08-23 13:14:27 +07:00
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
### Private Packagist Authentication
If you use Private Packagist for your private composer dependencies, you can set the `PACKAGIST_TOKEN` environment variable to authenticate.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
env:
PACKAGIST_TOKEN: ${{ secrets.PACKAGIST_TOKEN }}
```
### Manual Composer Authentication
In addition to GitHub or Private Packagist, if you want to authenticate private repositories hosted elsewhere, you can set the `COMPOSER_AUTH_JSON` environment variable with the authentication methods and the credentials in json format.
Please refer to the authentication section in [`composer documentation`](https://getcomposer.org/doc/articles/authentication-for-private-packages.md "composer documentation") for more details.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
env:
COMPOSER_AUTH_JSON: |
{
"http-basic": {
"example.org": {
"username": "${{ secrets.EXAMPLE_ORG_USERNAME }}",
"password": "${{ secrets.EXAMPLE_ORG_PASSWORD }}"
}
}
}
2020-02-21 15:09:04 +07:00
```
2019-12-28 01:53:51 +07:00
2021-08-23 13:14:27 +07:00
### Inline PHP Scripts
2020-02-29 22:38:26 +07:00
2021-08-23 13:14:27 +07:00
If you have to run multiple lines of PHP code in your workflow, you can do that easily without saving it to a file.
2020-04-10 00:48:37 +07:00
2021-08-23 13:14:27 +07:00
Put the code in the run property of a step and specify the shell as `php {0}`.
2020-04-10 00:48:37 +07:00
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
2021-08-23 13:14:27 +07:00
- name: Run PHP code
shell: php {0}
run: |
<?php
$welcome = "Hello, world";
echo $welcome;
2020-04-10 00:48:37 +07:00
```
2019-12-19 04:08:12 +07:00
### Problem Matchers
2020-10-19 18:36:48 +07:00
Problem matchers are `json` configurations which identify errors and warnings in your logs and surface them prominently in the GitHub Actions UI by highlighting them and creating code annotations.
2020-02-14 14:15:46 +07:00
#### PHP
Setup problem matchers for your `PHP` output by adding this step after the `setup-php` step.
2020-02-14 14:15:46 +07:00
```yaml
2020-02-21 15:09:04 +07:00
- name: Setup problem matchers for PHP
2020-02-14 14:15:46 +07:00
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"
```
2020-02-03 04:56:06 +07:00
#### PHPUnit
Setup problem matchers for your `PHPUnit` output by adding this step after the `setup-php` step.
2019-12-19 04:08:12 +07:00
```yaml
2020-02-21 15:09:04 +07:00
- name: Setup problem matchers for PHPUnit
2019-12-19 04:08:12 +07:00
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
```
#### PHPStan
2020-02-03 04:56:06 +07:00
2020-10-19 18:36:48 +07:00
PHPStan supports error reporting in GitHub Actions, so it does not require problem matchers.
2020-02-03 04:56:06 +07:00
```yaml
- name: Setup PHP
2020-02-14 14:15:46 +07:00
uses: shivammathur/setup-php@v2
2020-02-03 04:56:06 +07:00
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
tools: phpstan
2020-02-03 04:56:06 +07:00
- name: Run PHPStan
run: phpstan analyse src
2020-02-03 04:56:06 +07:00
```
#### Psalm
Psalm supports error reporting in GitHub Actions with an output format `github`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
tools: psalm
- name: Run Psalm
run: psalm --output-format=github
```
#### Tools with checkstyle support
For tools that support `checkstyle` reporting like `phpstan`, `psalm`, `php-cs-fixer` and `phpcs` you can use `cs2pr` to annotate your code.
For examples refer to the [cs2pr documentation](https://github.com/staabm/annotate-pull-request-from-checkstyle).
> Here is an example with `phpcs`.
```yaml
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
2023-11-23 18:42:56 +07:00
php-version: '8.3'
tools: cs2pr, phpcs
- name: Run phpcs
run: phpcs -q --report=checkstyle src | cs2pr
```
2019-10-03 17:43:34 +07:00
### Examples
2022-06-21 14:39:42 +07:00
Examples of using `setup-php` with various PHP frameworks and packages.
2019-10-03 17:43:34 +07:00
2022-02-02 13:56:25 +07:00
| Framework/Package | Runs on | Workflow |
|----------------------------------------|---------------------------------|---------------------------------------------------------------------------------------------------------------|
| Blackfire | `macOS`, `ubuntu` and `windows` | [blackfire.yml](./examples/blackfire.yml "GitHub Action using Blackfire") |
| Blackfire Player | `macOS`, `ubuntu` and `windows` | [blackfire-player.yml](./examples/blackfire-player.yml "GitHub Action using Blackfire Player") |
| CakePHP with `MySQL` and `Redis` | `ubuntu` | [cakephp-mysql.yml](./examples/cakephp-mysql.yml "GitHub Action for CakePHP with MySQL and Redis") |
| CakePHP with `PostgreSQL` and `Redis` | `ubuntu` | [cakephp-postgres.yml](./examples/cakephp-postgres.yml "GitHub Action for CakePHP with Postgres and Redis") |
| CakePHP without services | `macOS`, `ubuntu` and `windows` | [cakephp.yml](./examples/cakephp.yml "GitHub Action for CakePHP without services") |
| CodeIgniter | `macOS`, `ubuntu` and `windows` | [codeigniter.yml](./examples/codeigniter.yml "GitHub Action for CodeIgniter") |
| Laminas MVC | `macOS`, `ubuntu` and `windows` | [laminas-mvc.yml](./examples/laminas-mvc.yml "GitHub Action for Laminas Framework MVC Projects") |
| Laravel with `MySQL` and `Redis` | `ubuntu` | [laravel-mysql.yml](./examples/laravel-mysql.yml "GitHub Action for Laravel with MySQL and Redis") |
| Laravel with `PostgreSQL` and `Redis` | `ubuntu` | [laravel-postgres.yml](./examples/laravel-postgres.yml "GitHub Action for Laravel with PostgreSQL and Redis") |
| Laravel without services | `macOS`, `ubuntu` and `windows` | [laravel.yml](./examples/laravel.yml "GitHub Action for Laravel without services") |
| Lumen with `MySQL` and `Redis` | `ubuntu` | [lumen-mysql.yml](./examples/lumen-mysql.yml "GitHub Action for Lumen with MySQL and Redis") |
| Lumen with `PostgreSQL` and `Redis` | `ubuntu` | [lumen-postgres.yml](./examples/lumen-postgres.yml "GitHub Action for Lumen with PostgreSQL and Redis") |
| Lumen without services | `macOS`, `ubuntu` and `windows` | [lumen.yml](./examples/lumen.yml "GitHub Action for Lumen without services") |
| Phalcon with `MySQL` | `ubuntu` | [phalcon-mysql.yml](./examples/phalcon-mysql.yml "GitHub Action for Phalcon with MySQL") |
| Phalcon with `PostgreSQL` | `ubuntu` | [phalcon-postgres.yml](./examples/phalcon-postgres.yml "GitHub Action for Phalcon with PostgreSQL") |
| Roots/bedrock | `ubuntu` | [bedrock.yml](./examples/bedrock.yml "GitHub Action for Wordpress Development using @roots/bedrock") |
| Roots/sage | `ubuntu` | [sage.yml](./examples/sage.yml "GitHub Action for Wordpress Development using @roots/sage") |
| Slim Framework | `macOS`, `ubuntu` and `windows` | [slim-framework.yml](./examples/slim-framework.yml "GitHub Action for Slim Framework") |
| Symfony with `MySQL` | `ubuntu` | [symfony-mysql.yml](./examples/symfony-mysql.yml "GitHub Action for Symfony with MySQL") |
| Symfony with `PostgreSQL` | `ubuntu` | [symfony-postgres.yml](./examples/symfony-postgres.yml "GitHub Action for Symfony with PostgreSQL") |
| Symfony without services | `macOS`, `ubuntu` and `windows` | [symfony.yml](./examples/symfony.yml "GitHub Action for Symfony without services") |
| Yii2 Starter Kit with `MySQL` | `ubuntu` | [yii2-mysql.yml](./examples/yii2-mysql.yml "GitHub Action for Yii2 Starter Kit with MySQL") |
| Yii2 Starter Kit with `PostgreSQL` | `ubuntu` | [yii2-postgres.yml](./examples/yii2-postgres.yml "GitHub Action for Yii2 Starter Kit with PostgreSQL") |
2019-10-03 17:43:34 +07:00
2020-07-04 01:45:28 +07:00
## :bookmark: Versioning
2022-02-02 13:56:25 +07:00
- Use the `v2` tag as `setup-php` version. It is a rolling tag and is synced with the latest minor and patch releases. With `v2` you automatically get the bug fixes, security patches, new features and support for latest PHP releases.
2020-07-04 01:45:28 +07:00
- Semantic release versions can also be used. It is recommended to [use dependabot](https://docs.github.com/en/github/administering-a-repository/keeping-your-actions-up-to-date-with-github-dependabot "Setup Dependabot with GitHub Actions") with semantic versioning to keep the actions in your workflows up to date.
- Commit SHA can also be used, but are not recommended unless you set up tooling to update them with each release of the action.
- A new major version of the action will only be tagged when there are breaking changes in the setup-php API i.e. inputs, outputs, and environment flags.
2022-02-02 13:56:25 +07:00
- For debugging any issues `verbose` tag can be used temporarily. It outputs all the logs and is also synced with the latest releases.
2023-09-23 04:59:31 +07:00
- It is highly discouraged to use the `main` branch as version, it might break your workflow after major releases as they have breaking changes.
2024-01-01 03:25:48 +07:00
- If you are using the `v1` tag or a `1.x.y` version, you should [switch to v2](https://github.com/shivammathur/setup-php/wiki/Switch-to-v2 "Guide for switching from setup-php v1 to v2") as `v1` is not supported anymore.
2020-07-04 01:45:28 +07:00
## :scroll: License
2020-10-19 18:36:48 +07:00
- The scripts and documentation in this project are under the [MIT License](LICENSE "License for shivammathur/setup-php").
2020-08-02 20:35:44 +07:00
- This project has multiple [dependencies](#package-dependencies "Dependencies for this PHP Action"). Their licenses can be found in their respective repositories.
- The logo for `setup-php` is a derivative work of [php.net logo](https://www.php.net/download-logos.php) and is licensed under the [CC BY-SA 4.0 License](https://creativecommons.org/licenses/by-sa/4.0/ "Creative Commons License").
## :+1: Contributions
2019-09-06 07:18:51 +07:00
2020-07-04 01:45:28 +07:00
> Contributions are welcome!
- See [Contributor's Guide](.github/CONTRIBUTING.md "shivammathur/setup-php contribution guide") before you start.
2020-11-24 12:33:03 +07:00
- If you face any issues or want to suggest a feature/improvement, start a discussion [here](https://github.com/shivammathur/setup-php/discussions "Setup PHP discussions").
2019-09-06 07:18:51 +07:00
2021-06-10 15:14:58 +07:00
*Contributors of `setup-php` and other related projects*
2020-08-19 08:19:39 +07:00
<p align="center">
<a href="https://github.com/shivammathur/setup-php/graphs/contributors">
2021-06-10 15:14:58 +07:00
<img src="https://setup-php.com/contributors/?" alt="Contributors of setup-php and related projects" width="100%">
2020-08-19 08:19:39 +07:00
</a>
</p>
2020-02-14 14:15:46 +07:00
## :sparkling_heart: Support This Project
2022-02-02 13:56:25 +07:00
- Please star the project and share it. If you blog, please share your experience of using `setup-php`.
- Please [reach out](mailto:contact@setup-php.com) if you have any questions about sponsoring setup-php.
2021-12-26 08:25:07 +07:00
Many users and organisations support setup-php via [GitHub Sponsors](https://github.com/sponsors/shivammathur).
2020-08-13 01:21:33 +07:00
2021-12-26 08:25:07 +07:00
<a href="https://github.com/sponsors/shivammathur"><img src="https://setup-php.com/sponsors.svg?" alt="Sponsor shivammathur"></a>
2019-11-03 11:41:44 +07:00
2021-12-26 08:25:07 +07:00
These companies generously provide setup-php their products and services to aid in the development of this project.
2021-09-08 13:49:06 +07:00
2021-12-26 08:25:07 +07:00
<p>
<a href="https://www.jetbrains.com/?from=setup-php">
2024-02-24 13:04:19 +07:00
<img src="https://setup-php.com/sponsors/jetbrains.svg" alt="JetBrains" width="212" height="120">
2021-12-26 08:25:07 +07:00
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://www.macstadium.com/opensource/members#gh-light-mode-only">
2024-02-24 13:04:19 +07:00
<img src="https://setup-php.com/sponsors/macstadium.png" alt="Mac Stadium" width="296" height="120">
2021-12-26 08:25:07 +07:00
</a>
<a href="https://www.macstadium.com/opensource/members#gh-dark-mode-only">
2024-02-24 13:04:19 +07:00
<img src="https://setup-php.com/sponsors/macstadium-white.png" alt="Mac Stadium" width="296" height="120">
2021-12-26 08:25:07 +07:00
</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="https://tidelift.com/subscription/pkg/npm-setup-php">
2024-02-24 13:04:19 +07:00
<img src="https://setup-php.com/sponsors/tidelift.png" alt="Tidelift" width="140" height="120">
2022-04-05 00:23:28 +07:00
</a>
2021-09-08 13:49:06 +07:00
</p>
2020-07-04 01:45:28 +07:00
## :package: Dependencies
2020-02-14 14:15:46 +07:00
- [Node.js dependencies](https://github.com/shivammathur/setup-php/network/dependencies "Node.js dependencies")
2020-10-30 12:58:54 +07:00
- [aaronparker/VcRedist](https://github.com/aaronparker/VcRedist "VcRedist PowerShell package")
2019-12-09 09:39:03 +07:00
- [mlocati/powershell-phpmanager](https://github.com/mlocati/powershell-phpmanager "Package to handle PHP on windows")
2020-02-14 14:15:46 +07:00
- [ppa:ondrej/php](https://launchpad.net/~ondrej/+archive/ubuntu/php "Packaging active PHP packages")
- [shivammathur/cache-extensions](https://github.com/shivammathur/cache-extensions "GitHub action to help with caching PHP extensions")
2020-08-10 15:13:18 +07:00
- [shivammathur/composer-cache](https://github.com/shivammathur/composer-cache "Cache composer releases")
2020-07-04 01:45:28 +07:00
- [shivammathur/homebrew-extensions](https://github.com/shivammathur/homebrew-extensions "Tap for PHP extensions on MacOS")
2020-08-10 15:13:18 +07:00
- [shivammathur/homebrew-php](https://github.com/shivammathur/homebrew-php "Tap for PHP builds on MacOS")
2020-08-19 08:19:39 +07:00
- [shivammathur/icu-intl](https://github.com/shivammathur/icu-intl "icu4c and php-intl builds")
2020-08-10 15:13:18 +07:00
- [shivammathur/php-builder](https://github.com/shivammathur/php-builder "Nightly PHP package for Ubuntu")
- [shivammathur/php-builder-windows](https://github.com/shivammathur/php-builder-windows "Nightly PHP package for Windows")
- [shivammathur/php-ubuntu](https://github.com/shivammathur/php-ubuntu "Cache stable PHP Packages for Ubuntu")
2021-08-23 13:14:27 +07:00
- [shivammathur/php5-darwin](https://github.com/shivammathur/php5-darwin "Scripts to set up PHP5 versions on darwin")
- [shivammathur/php5-ubuntu](https://github.com/shivammathur/php5-ubuntu "Scripts to set up PHP5 versions on ubuntu")
## :bookmark_tabs: Further Reading
2019-09-06 07:18:51 +07:00
2019-10-10 19:17:17 +07:00
- [About GitHub Actions](https://github.com/features/actions "GitHub Actions")
- [GitHub Actions Syntax](https://help.github.com/en/articles/workflow-syntax-for-github-actions "GitHub Actions Syntax")
2020-08-13 01:21:33 +07:00
- [Other Awesome Actions](https://github.com/sdras/awesome-actions "List of Awesome GitHub Actions")
<!-- Links to tools -->
[`behat`]: https://docs.behat.org/en/latest/
[`blackfire`]: https://blackfire.io/docs/php/index
[`blackfire-player`]: https://blackfire.io/docs/builds-cookbooks/player
[`box`]: https://github.com/humbug/box
2023-06-23 21:13:17 +07:00
[`castor`]: https://github.com/jolicode/castor
2022-01-29 05:07:30 +07:00
[`churn`]: https://github.com/bmitch/churn-php
[`codeception`]: https://codeception.com/
[`composer`]: https://getcomposer.org/
[`composer-normalize`]: https://github.com/ergebnis/composer-normalize
[`composer-prefetcher`]: https://github.com/narrowspark/automatic-composer-prefetcher
[`composer-require-checker`]: https://github.com/maglnet/ComposerRequireChecker
[`composer-unused`]: https://github.com/composer-unused/composer-unused
[`cs2pr`]: https://github.com/staabm/annotate-pull-request-from-checkstyle
[`deployer`]: https://deployer.org/
[`flex`]: https://flex.symfony.com/
[`grpc_php_plugin`]: https://grpc.io/
[`infection`]: https://infection.github.io/
[`parallel-lint`]: https://github.com/php-parallel-lint/PHP-Parallel-Lint
[`pecl`]: https://pecl.php.net/
[`phan`]: https://github.com/phan/phan/wiki
[`phing`]: https://www.phing.info/
[`phinx`]: https://phinx.org/
[`phive`]: https://phar.io/
[`php-config`]: https://www.php.net/manual/en/install.pecl.php-config.php
[`php-cs-fixer`]: https://cs.symfony.com/
[`php-scoper`]: https://github.com/humbug/php-scoper
[`phpcbf`]: https://github.com/PHPCSStandards/php_codesniffer
[`phpcpd`]: https://github.com/sebastianbergmann/phpcpd
[`phpcs`]: https://github.com/PHPCSStandards/php_codesniffer
[`phpdoc`]: https://phpdoc.org/
[`phpDocumentor`]: https://phpdoc.org/
[`phpize`]: https://www.php.net/manual/en/install.pecl.phpize.php
[`phplint`]: https://github.com/overtrue/phplint
[`phpmd`]: https://phpmd.org/
[`phpspec`]: https://www.phpspec.net/
[`phpstan`]: https://phpstan.org/
[`phpunit`]: https://phpunit.de/
[`phpunit-bridge`]: https://symfony.com/doc/current/components/phpunit_bridge.html
[`phpunit-polyfills`]: https://github.com/Yoast/PHPUnit-Polyfills
2022-07-11 16:29:13 +07:00
[`pint`]: https://github.com/laravel/pint
[`prestissimo`]: https://github.com/hirak/prestissimo
[`protoc`]: https://developers.google.com/protocol-buffers/
[`psalm`]: https://psalm.dev/
[`rector`]: https://getrector.org/
[`symfony`]: https://symfony.com/download
[`symfony-cli`]: https://symfony.com/download
[`vapor`]: https://docs.vapor.build/
[`vapor-cli`]: https://docs.vapor.build/
[`wp`]: https://wp-cli.org/
[`wp-cli`]: https://wp-cli.org/