Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer in 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 section and examples to see how to use this.
Both GitHub-hosted and self-hosted runners are supported by setup-php on the following OS/Platforms.
| Virtual environment | Arch | YAML workflow label | Pre-installed PHP |
|---|---|---|---|
| Ubuntu 24.04 | x86_64 | ubuntu-latest or ubuntu-24.04 |
PHP 8.3 |
| Ubuntu 22.04 | x86_64 | ubuntu-22.04 |
PHP 8.1 |
| Ubuntu 24.04 | aarch64 | ubuntu-24.04-arm |
PHP 8.3 |
| Ubuntu 22.04 | aarch64 | ubuntu-22.04-arm |
PHP 8.1 |
| Windows Server 2025 | x64 | windows-2025 |
PHP 8.5 |
| Windows Server 2022 | x64 | windows-latest or windows-2022 |
PHP 8.5 |
| macOS Tahoe 26.x | arm64 | macos-26 |
- |
| macOS Sequoia 15.x | arm64 | macos-latest or macos-15 |
- |
| macOS Sonoma 14.x | arm64 | macos-14 |
- |
| macOS Tahoe 26.x | x86_64 | macos-26-intel |
PHP 8.5 |
| macOS Sequoia 15.x | x86_64 | macos-15-intel |
PHP 8.5 |
| Host OS/Virtual environment | YAML workflow label |
|---|---|
| Ubuntu 24.04 | self-hosted or Linux |
| Ubuntu 22.04 | self-hosted or Linux |
| Debian 13 | self-hosted or Linux |
| Debian 12 | self-hosted or Linux |
| Debian 11 | self-hosted or Linux |
| Windows 7 and newer | self-hosted or Windows |
| Windows Server 2012 R2 and newer | self-hosted or Windows |
| macOS Tahoe 26.x x86_64/arm64 | self-hosted or macOS |
| macOS Sequoia 15.x x86_64/arm64 | self-hosted or macOS |
| macOS Sonoma 14.x x86_64/arm64 | self-hosted or macOS |
setup-php switches to it, otherwise it installs the PHP version.On all supported OS/Platforms, the following PHP versions can be set up as per the runner.
| 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 |
8.0 |
Stable |
End of life |
GitHub-hosted, self-hosted |
8.1 |
Stable |
End of life |
GitHub-hosted, self-hosted |
8.2 |
Stable |
Security fixes only |
GitHub-hosted, self-hosted |
8.3 |
Stable |
Security fixes only |
GitHub-hosted, self-hosted |
8.4 |
Stable |
Active |
GitHub-hosted, self-hosted |
8.5 |
Stable |
Active |
GitHub-hosted, self-hosted |
8.6 |
Nightly |
In development |
GitHub-hosted, self-hosted |
[!Note] - Specifying
8.6inphp-versioninput installs a nightly build ofPHP 8.6.0-devfrom the master branch of PHP. See nightly build setup for more information. - To use JIT onPHP 8.0and above, refer to the JIT configuration section.
PHP extensions can be set up using the extensions input. It accepts a string in csv-format.
Ubuntu, extensions which are available as a package, available on PECL or a git repository can be set up.- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: imagick, redis
On Windows, extensions available on PECL which have the DLL binary can be set up.
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.
Extensions installed along with PHP if specified are enabled.
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.
- name: Setup PHP with specific version of PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '5.4'
extensions: swoole-1.9.3
PECL can be set up by suffixing the extension's name with its state i.e alpha, beta, devel or snapshot.- name: Setup PHP with pre-release PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: xdebug-beta
On Ubuntu and macOS to compile and install an extension from PECL with libraries or custom configuration follow this guide.
Shared extensions can be disabled by prefixing them with a :. All extensions depending on the specified extension will also be disabled.
- name: Setup PHP and disable opcache
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: :mbstring
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.This disables all core and third-party shared extensions and thus, can break some tools that 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.
- name: Setup PHP without any shared extensions except mbstring
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: none, mbstring
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 for PHP 8.4 and lower, ICU 57.2 and newer versions are supported for PHP 8.5 and above. Refer to ICU builds for the specific versions supported.- name: Setup PHP with intl
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: intl-77.1
Extensions loaded by default after setup-php runs can be found on the wiki.
These extensions have custom support:
cubrid and pdo_cubrid on Ubuntu.event, gearman, geos and relay on Ubuntu and macOS.blackfire, couchbase, ibm_db2, ioncube, oci8, pdo_firebird, pdo_ibm, pdo_oci, pecl_http, phalcon3, phalcon4, phalcon5, and zephir_parser on all supported OS.
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.
- name: Setup PHP with fail-fast
uses: shivammathur/setup-php@v2
with:
php-version: '8.5'
extensions: oci8
env:
fail-fast: true
These tools can be set up globally using the tools input. It accepts a string in csv-format.
[backward-compatibility-check], [behat], [blackfire], [blackfire-player], [box], [castor], [churn], [codeception], [composer], [composer-dependency-analyser], [composer-normalize], [composer-prefetcher], [composer-require-checker], [composer-unused], [cs2pr], [deployer], [ecs], [flex], [grpc_php_plugin], [infection], [mago], [name-collision-detector], [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], [pie], [pint], [prestissimo], [protoc], [psalm], [rector], [symfony] or [symfony-cli], [vapor] or [vapor-cli], [wp] or [wp-cli]
```yaml - name: Setup PHP with tools uses: shivam
$ claude mcp add setup-php \
-- python -m otcore.mcp_server <graph>