Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

License

NotificationsYou must be signed in to change notification settings

shivammathur/setup-php

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Setup PHP in GitHub Actions

Setup PHP in GitHub Actions

GitHub Actions statusCodecov Code CoverageLICENSEPHP Versions Supported

setup-php redditsetup-php twittersetup-php status

Setup PHP with required extensions, php.ini configuration, code-coverage support and various tools like composer inGitHub Actions. This action gives you a cross-platform interface to set up the PHP environment you need to test your application. Refer toUsage section andexamples to see how to use this.

Contents

☁️ OS/Platform Support

BothGitHub-hosted andself-hosted runners are supported bysetup-php on the following OS/Platforms.

GitHub-Hosted Runners

Virtual environmentArchYAML workflow labelPre-installed PHP
Ubuntu 24.04x86_64ubuntu-latest orubuntu-24.04PHP 8.3
Ubuntu 22.04x86_64ubuntu-22.04PHP 8.1
Ubuntu 24.04aarch64ubuntu-24.04-armPHP 8.3
Ubuntu 22.04aarch64ubuntu-22.04-armPHP 8.1
Windows Server 2025x64windows-2025PHP 8.3
Windows Server 2022x64windows-latest orwindows-2022PHP 8.3
macOS Tahoe 26.xarm64macos-26-
macOS Sequoia 15.xarm64macos-latest ormacos-15-
macOS Sonoma 14.xarm64macos-14-
macOS Sequoia 15.xx86_64macos-15-intelPHP 8.3
macOS Ventura 13.xx86_64macos-13PHP 8.3

Self-Hosted Runners

Host OS/Virtual environmentYAML workflow label
Ubuntu 24.04self-hosted orLinux
Ubuntu 22.04self-hosted orLinux
Debian 13self-hosted orLinux
Debian 12self-hosted orLinux
Debian 11self-hosted orLinux
Windows 7 and newerself-hosted orWindows
Windows Server 2012 R2 and newerself-hosted orWindows
macOS Tahoe 26.x x86_64/arm64self-hosted ormacOS
macOS Sequoia 15.x x86_64/arm64self-hosted ormacOS
macOS Sonoma 14.x x86_64/arm64self-hosted ormacOS
  • Refer to theself-hosted setup to use the action on self-hosted runners.
  • Operating systems based on the above Ubuntu and Debian versions are also supported on best effort basis.
  • If the requested PHP version is pre-installed,setup-php switches to it, otherwise it installs the PHP version.

🎉 PHP Support

On all supported OS/Platforms, the following PHP versions can be set up as per the runner.

  • PHP 5.3 to PHP 8.6 on GitHub-hosted runners, except for macOS ARM64 runners (macos-14).
  • PHP 5.6 to PHP 8.6 on GitHub-hosted macOS ARM64 runners (macos-14).
  • PHP 5.6 to PHP 8.6 on self-hosted runners.
PHP VersionStabilityRelease SupportRunner Support
5.3StableEnd of lifeGitHub-hosted
5.4StableEnd of lifeGitHub-hosted
5.5StableEnd of lifeGitHub-hosted
5.6StableEnd of lifeGitHub-hosted,self-hosted
7.0StableEnd of lifeGitHub-hosted,self-hosted
7.1StableEnd of lifeGitHub-hosted,self-hosted
7.2StableEnd of lifeGitHub-hosted,self-hosted
7.3StableEnd of lifeGitHub-hosted,self-hosted
7.4StableEnd of lifeGitHub-hosted,self-hosted
8.0StableEnd of lifeGitHub-hosted,self-hosted
8.1StableSecurity fixes onlyGitHub-hosted,self-hosted
8.2StableSecurity fixes onlyGitHub-hosted,self-hosted
8.3StableActiveGitHub-hosted,self-hosted
8.4StableActiveGitHub-hosted,self-hosted
8.5StableActiveGitHub-hosted,self-hosted
8.6NightlyIn developmentGitHub-hosted,self-hosted

Note

  • Specifying8.6 inphp-version input installs a nightly build ofPHP 8.6.0-dev from the master branch of PHP. Seenightly build setup for more information.
  • To use JIT onPHP 8.0 and above, refer to theJIT configuration section.

➕ PHP Extension Support

PHP extensions can be set up using theextensions input. It accepts astring in csv-format.

  • OnUbuntu, extensions which are available as a package, available onPECL or a git repository can be set up.
-name:Setup PHP with PECL extensionuses:shivammathur/setup-php@v2with:php-version:'8.5'extensions:imagick, redis
  • OnWindows, extensions available onPECL which have theDLL binary can be set up.

  • OnmacOS, extensions available onPECL or a git repository can be set up.

  • OnUbuntu andmacOS to compile and install an extension from a git repository follow thisguide.

  • Extensions installed along with PHP if specified are enabled.

  • Specific versions of extensions available onPECL 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 extensionuses:shivammathur/setup-php@v2with:php-version:'5.4'extensions:swoole-1.9.3
  • Extensions with pre-release versions available onPECL can be set up by suffixing the extension's name with its state i.ealpha,beta,devel orsnapshot.
-name:Setup PHP with pre-release PECL extensionuses:shivammathur/setup-php@v2with:php-version:'8.5'extensions:xdebug-beta
  • OnUbuntu andmacOS to compile and install an extension from PECL with libraries or custom configuration follow thisguide.

  • 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 opcacheuses:shivammathur/setup-php@v2with:php-version:'8.5'extensions::mbstring
  • All shared extensions can be disabled by specifyingnone. Whennone 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 afternone in theextensions input to avoid any issues.

-name:Setup PHP without any shared extensions except mbstringuses:shivammathur/setup-php@v2with:php-version:'8.5'extensions:none, mbstring
  • Extensionintl can be set up with specificICU version forPHP 5.6 and above inUbuntu workflows by suffixingintl with theICU 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 toICU builds for the specific versions supported.
-name:Setup PHP with intluses:shivammathur/setup-php@v2with:php-version:'8.5'extensions:intl-77.1
  • Extensions loaded by default aftersetup-php runs can be found on thewiki.

  • These extensions have custom support:

    • cubrid andpdo_cubrid onUbuntu.
    • event,gearman,geos andrelay onUbuntu andmacOS.
    • blackfire,couchbase,ibm_db2,ioncube,oci8,pdo_firebird,pdo_ibm,pdo_oci,pecl_http,phalcon3,phalcon4,phalcon5, andzephir_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 setfail-fast flag totrue.

-name:Setup PHP with fail-fastuses:shivammathur/setup-php@v2with:php-version:'8.5'extensions:oci8env:fail-fast:true

🔧 Tools Support

These tools can be set up globally using thetools 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 orphpDocumentor,phpize,phplint,phpmd,phpspec,phpstan,phpunit,phpunit-bridge,phpunit-polyfills,pie,pint,prestissimo,protoc,psalm,rector,symfony orsymfony-cli,vapor orvapor-cli,wp orwp-cli

-name:Setup PHP with toolsuses:shivammathur/setup-php@v2with:php-version:'8.5'tools:php-cs-fixer, phpunit
  • In addition to above tools any composer tool or package can also be set up globally by specifying it asvendor/package matching the listing on Packagist. This format accepts the sameversion constraints ascomposer.
-name:Setup PHP with toolsuses:shivammathur/setup-php@v2with:php-version:'8.5'tools:vimeo/psalm
  • To set up a particular version of a tool, specify it in the formtool:version.

    Version can be in the following format:

    • Semver. For exampletool:1.2.3 ortool:1.2.3-beta1.
    • Major version. For exampletool:1 ortool:1.x.
    • Major and minor version. For exampletool:1.2 ortool:1.2.x.

    When you specify just the major version or the version inmajor.minor format, the latest patch version matching the input will be setup.

  • The latest stable version ofcomposer is set up by default. You can set up the requiredcomposer version by specifying the major versionv1 orv2, or the version inmajor.minor orsemver format. Additionally, for composersnapshot andpreview can also be specified to set up the respective releases.

-name:Setup PHP with composer v2uses:shivammathur/setup-php@v2with:php-version:'8.5'tools:composer:v1
  • If you do not use composer in your workflow, you can specifytools: none to skip it.
-name:Setup PHP without composeruses:shivammathur/setup-php@v2with:php-version:'8.5'tools:none
  • Toolspear,pecl,phpize andphp-config are set up by default for all supported PHP versions on Linux and macOS.

  • The latest version ofblackfire cli is set up whenblackfire is specified in tools input. Please refer to theofficial documentation for usingblackfire with GitHub Actions.

  • Toolsprestissimo andcomposer-prefetcher will be skipped unlesscomposer:v1 is also specified in tools input. It is recommended to dropprestissimo and usecomposer v2.

  • By default, exceptcomposer 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 setfail-fast flag totrue.

-name:Setup PHP with fail-fastuses:shivammathur/setup-php@v2with:php-version:'8.5'tools:deployerenv:fail-fast:true
  • By default,composer blocks all its plugins. If you are using thetools input to install a composer plugin it will be added to the allow list, alternatively if your dependencies have composer plugins, you can allow them by settingCOMPOSER_ALLOW_PLUGINS that accepts a csv string of plugin names.
-name:Setup PHP with fail-fastuses:shivammathur/setup-php@v2with:php-version:'8.5'env:COMPOSER_ALLOW_PLUGINS:composer/installers, composer/satis

Note

  • Inputtools is useful to set up tools which are only used in CI workflows, thus keeping yourcomposer.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 usingtools input to speed up your workflow.
  • By default,COMPOSER_NO_INTERACTION is set to1 andCOMPOSER_PROCESS_TIMEOUT is set to0. In effect, this means that Composer commands in your scripts do not need to specify--no-interaction.
  • Also,COMPOSER_NO_AUDIT is set to1. So if you want to audit your dependencies for security vulnerabilities, it is recommended to add acomposer audit step before you install them.
  • If you want to set a differentCOMPOSER_PROCESS_TIMEOUT, you can set it in your workflow file using theenv keyword.
-name:Setup PHP with composer and custom process timeoutuses:shivammathur/setup-php@v2with:php-version:'8.5'env:COMPOSER_PROCESS_TIMEOUT:300

📶 Coverage Support

Xdebug

Specifycoverage: xdebug to useXdebug and disablePCOV.
Runs on allPHP versions supported.

-name:Setup PHP with Xdebuguses:shivammathur/setup-php@v2with:php-version:'8.5'coverage:xdebug
  • When you specifycoverage: xdebug, the latest version of Xdebug compatible with the PHP version is set up by default.
  • If you need Xdebug 2.x on PHP 7.2, 7.3 or 7.4, you can specifycoverage: xdebug2.
-name:Setup PHP with Xdebug 2.xuses:shivammathur/setup-php@v2with:php-version:'7.4'coverage:xdebug2

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 thedisable coverage section for details.

PCOV

Specifycoverage: pcov to usePCOV and disableXdebug.
Runs on PHP 7.1 and newer PHP versions.

  • If your source code directory is other thansrc,lib or,app, specifypcov.directory using theini-values input.
-name:Setup PHP with PCOVuses:shivammathur/setup-php@v2with:php-version:'8.5'ini-values:pcov.directory=api#optional, see above for usage.coverage:pcov
  • PHPUnit 8.x and above support PCOV out of the box.
  • If you are using PHPUnit 5.x, 6.x or 7.x, you need to set uppcov/clobber before executing your tests.
-name:Setup PCOVrun:|    composer require pcov/clobber    vendor/bin/pcov clobber

Disable Coverage

Specifycoverage: none to disable bothXdebug andPCOV.

Disable coverage for these reasons:

  • You are not generating coverage reports while testing.
  • You are usingphpdbg for running your tests.
  • You are profiling your code usingblackfire.
  • You are using PHP in JIT mode. Please refer toJIT configuration section for more details.
-name:Setup PHP with no coverage driveruses:shivammathur/setup-php@v2with:php-version:'8.5'coverage:none

📝 Usage

Inputs

Specify usingwith keyword

php-version (optional)

  • Specify the PHP version you want to set up.
  • Accepts astring. For example'8.5'.
  • Acceptslowest to set up the lowest supported PHP version.
  • Acceptshighest orlatest to set up the latest stable PHP version.
  • Acceptsnightly to set up a nightly build from the master branch of PHP.
  • Acceptspre-installed to set up the highest pre-installed PHP version. You can combine this withupdate: true to update the pre-installed PHP version.
  • Accepts the formatd.x, whered is the major version. For example5.x,7.x and8.x.
  • SeePHP support for the supported PHP versions.
  • If not specified, it looks for the following in order:
    • Thephp-version-file input if it exists
    • Acomposer.lock file and theplatform-overrides.php value
    • Acomposer.json file and theconfig.platform.php value
    • If thecomposer.lock orcomposer.json file is in a subdirectory in your repository, please specify the subdirectory path inCOMPOSER_PROJECT_DIR env.

php-version-file (optional)

  • Specify a file with the PHP version you want to set up.
  • Accepts astring. For example'.phpenv-version'.
  • SeePHP support for the supported PHP versions.
  • By default,.php-version file is used.
  • The file needs to either have the PHP version as its content or follows the asdf.tool-versions format.
  • If not specified and the default.php-version file is not found, the latest stable PHP version is set up.

extensions (optional)

  • Specify the extensions you want to add or disable.
  • Accepts astring in csv-format. For examplembstring, :opcache.
  • Acceptsnone to disable all shared extensions.
  • Shared extensions prefixed with: are disabled.
  • SeePHP extension support for more info.

ini-file (optional)

  • Specify the basephp.ini file.
  • Acceptsproduction,development ornone.
  • By default, productionphp.ini file is used.

ini-values (optional)

  • Specify the values you want to add tophp.ini.
  • Accepts astring in csv-format. For examplepost_max_size=256M, max_execution_time=180.
  • Accepts ini values with commas if wrapped in quotes. For examplexdebug.mode="develop,coverage".

coverage (optional)

  • Specify the code-coverage driver you want to set up.
  • Acceptsxdebug,pcov ornone.
  • Seecoverage support for more info.

tools (optional)

  • Specify the tools you want to set up.
  • Accepts astring in csv-format. For example:phpunit, phpcs
  • Seetools support for tools supported.

github-token (optional)

  • Specify the GitHub token to use for authentication.
  • Accepts astring.
  • By default,GITHUB_TOKEN secret provided by GitHub Actions is used.
  • For GitHub Enterprise users, it is recommended to use a Personal Access Token (PAT).

Outputs

php-version

On GitHub Actions you can assign thesetup-php step anid, you can use the same to get the outputs in a later step.

  • Provides the PHP version in semver format.
-name:Setup PHPid:setup-phpuses:shivammathur/setup-php@v2with:php-version:'8.5'-name:Print PHP versionrun:echo ${{ steps.setup-php.outputs.php-version }}

Flags

Specify usingenv 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 tofalse.
  • Acceptstrue andfalse.

phpts (optional)

  • Specify to set up a thread-safe build of PHP.
  • Acceptsnts for non-thread-safe andzts orts for thread-safe.
  • By default, it is set tonts.
  • Seethread safe setup for more info.

update (optional)

  • Specify to update PHP on the runner to the latest patch version.
  • Acceptstrue andfalse.
  • By default, it is set tofalse.
  • Seeforce update setup for more info.

See below for more info.

Basic Setup

Set up a particular PHP version.

steps:-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'extensions:mbstring, intlini-values:post_max_size=256M, max_execution_time=180coverage:xdebugtools:php-cs-fixer, phpunit

Matrix Setup

Set up multiple PHP versions on multiple operating systems.

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:10steps:    -name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:${{ matrix.php-versions }}extensions:mbstring, intlini-values:post_max_size=256M, max_execution_time=180coverage:xdebugtools:php-cs-fixer, phpunit:${{ matrix.phpunit-versions }}

Nightly Build Setup

Set up a nightly build ofPHP 8.6.

  • These PHP versions are currently in active development and might contain bugs and breaking changes.
  • Some user space extensions might not support these versions currently.
steps:-name:Setup nightly PHPuses:shivammathur/setup-php@v2with:php-version:'8.6'extensions:mbstringini-values:post_max_size=256M, max_execution_time=180coverage:xdebugtools:php-cs-fixer, phpunit

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 thedebug environment variable to set up a build with debugging symbols for PHP 5.6 and above.

Note

  • On Linux, the debug symbols are added asdebug info files in the/usr/lib/debug/.build-id directory. These files match thebuild-id in the ELF section of the PHP binaries and debugging tools likegdb are able to resolve the symbols from these files.
  • On Windows, the debug symbols are added aspdb files in the PHP installation directory.
  • On macOS, the debug symbols are compiled into the binaries.
steps:-name:Setup PHP with debugging symbolsuses:shivammathur/setup-php@v2with:php-version:'8.5'env:debug:true# specify true or false

Thread Safe Setup

Set upTS orNTS PHP.

  • NTS versions are set up by default.
jobs:run:runs-on:[ubuntu-latest, windows-latest, macos-latest]name:Setup PHP TSsteps:    -name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'env:phpts:ts# specify ts or nts

Force Update Setup

Update to the latest patch of PHP versions.

  • Pre-installed PHP versions are not updated to their latest patch release by default.
  • Ifppa:ondrej/php is missing on the Ubuntu GitHub environment, the PHP version is updated to the latest patch release.
  • You can specify theupdate environment variable totrue for updating to the latest release.
-name:Setup PHP with latest versionsuses:shivammathur/setup-php@v2with:php-version:'8.5'env:update:true# specify true or false

Verbose Setup

Debug your workflow

To debug any issues, you can use theverbose tag instead ofv2.

-name:Setup PHP with logsuses:shivammathur/setup-php@verbosewith:php-version:'8.5'

Multi-Arch Setup

Set up PHP on multiple architecture on Ubuntu GitHub Runners.

  • PHP 5.6 toPHP 8.5 are supported bysetup-php on multiple architecture onUbuntu andDebian.
  • For this, you can useshivammathur/node images as containers. These have compatibleNodejs andPHP installed forsetup-php.
jobs:run:runs-on:${{ matrix.os }}container:shivammathur/node:php-${{ matrix.php-versions }}-24.04-${{ matrix.arch }}strategy:matrix:arch:["amd64", "arm64v8"]php-versions:[8.4, 8.5]include:            -arch:"amd64"os:"ubuntu-24.04"            -arch:"arm64v8"os:"ubuntu-24.04-arm"steps:      -name:Install PHPuses:shivammathur/setup-php@v2with:php-version:${{ matrix.php-versions }}

Self Hosted Setup

Set up PHP on a self-hosted runner.

  • To set up a containerised self-hosted runner, refer to the following guides as per your base operating system.

  • To set up the runner directly on the host OS or in a virtual machine, follow thisrequirements guide before setting up the self-hosted runner.

  • If your workflow usesservice containers, 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.

It is recommended to specify the environment variablerunner with the valueself-hosted for self-hosted environments.

jobs:run:runs-on:self-hostedstrategy: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 PHPuses:shivammathur/setup-php@v2with:php-version:${{ matrix.php-versions }}env:runner:self-hosted

Note

  • 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 of your development environment or your production server.
  • Avoid using the same labels for yourself-hosted runners which are used byGitHub-hosted runners.

Local Testing Setup

Test yourUbuntu workflow locally usingnektos/act.

jobs:run:runs-on:ubuntu-lateststeps:    -name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'

Run the workflow locally withact usingshivammathur/node docker images.

Choose the image tag which matches theruns-on property in your workflow. For example, if you are usingubuntu-22.04 in your workflow, runact -P ubuntu-22.04=shivammathur/node:22.04.

# For runs-on: ubuntu-latestact -P ubuntu-latest=shivammathur/node:latest# For runs-on: ubuntu-24.04act -P ubuntu-24.04=shivammathur/node:24.04# For runs-on: ubuntu-22.04act -P ubuntu-22.04=shivammathur/node:22.04

JIT Configuration

Enable Just-in-time (JIT) on PHP 8.0 and above.

  • To enable JIT, enableopcache in cli mode by settingopcache.enable_cli=1.
  • JIT conflicts withXdebug,PCOV, and other extensions which overridezend_execute_ex function, so setcoverage: none and disable any such extension if added.
  • By default,opcache.jit=1235 andopcache.jit_buffer_size=256M (opcache.jit_buffer_size=128M on ARM-based environments) are set which can be changed usingini-values input.
  • For detailed information about JIT related directives refer to theofficial PHP documentation.

For example to enable JIT intracing mode with buffer size of64 MB.

-name:Setup PHP with JIT in tracing modeuses:shivammathur/setup-php@v2with:php-version:'8.5'coverage:noneini-values:opcache.enable_cli=1, opcache.jit=tracing, opcache.jit_buffer_size=64M

Cache Extensions

You can cache PHP extensions usingshivammathur/cache-extensions andaction/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 toshivammathur/cache-extensions for details.

Cache Composer Dependencies

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.

-name:Get composer cache directoryid:composer-cacherun:echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT-name:Cache dependenciesuses:actions/cache@v4with:path:${{ steps.composer-cache.outputs.dir }}key:${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}restore-keys:${{ runner.os }}-composer--name:Install dependenciesrun:composer install --prefer-dist

Note

  • Please do not cachevendor directory usingaction/cache as that will have side effects.
  • If you do not commitcomposer.lock, you can use the hash ofcomposer.json as the key for your cache.
key:${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
  • If you support a range ofcomposer dependencies and useprefer-lowest andprefer-stable options, you can store them in your matrix and add them to the keys.
key:${{ runner.os }}-composer-${{ matrix.prefer }}-${{ hashFiles('**/composer.lock') }}restore-keys:${{ runner.os }}-composer-${{ matrix.prefer }}-

GitHub Composer Authentication

By default, setup-php uses theGITHUB_TOKEN secret that is generated for each workflow run. In case you want to use a Personal Access Token (PAT) instead, you can set thegithub-token input.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'github-token:${{ secrets.YOUR_PAT_TOKEN }}

TheCOMPOSER_TOKEN andGITHUB_TOKEN environment variables have been deprecated in favor of thegithub-token input and will be removed in the next major version.

For GitHub Enterprise users, thegithub-token input does not default to theGITHUB_TOKEN secret. Therefore, it's recommended to set thegithub-token input to a Personal Access Token (PAT).

Private Packagist Authentication

If you use Private Packagist for your private composer dependencies, you can set thePACKAGIST_TOKEN environment variable to authenticate.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'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 theCOMPOSER_AUTH_JSON environment variable with the authentication methods and the credentials in json format.Please refer to the authentication section incomposer documentation for more details.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'env:COMPOSER_AUTH_JSON:|      {        "http-basic": {          "example.org": {            "username": "${{ secrets.EXAMPLE_ORG_USERNAME }}",            "password": "${{ secrets.EXAMPLE_ORG_PASSWORD }}"          }        }      }

Inline PHP Scripts

If you have to run multiple lines of PHP code in your workflow, you can do that easily without saving it to a file.

Put the code in the run property of a step and specify the shell asphp {0}.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'-name:Run PHP codeshell:php {0}run:|    <?php    $welcome = "Hello, world";    echo $welcome;

Problem Matchers

Problem matchers arejson 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.

PHP

Setup problem matchers for yourPHP output by adding this step after thesetup-php step.

-name:Setup problem matchers for PHPrun:echo "::add-matcher::${{ runner.tool_cache }}/php.json"

PHPUnit

Setup problem matchers for yourPHPUnit output by adding this step after thesetup-php step.

-name:Setup problem matchers for PHPUnitrun:echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

PHPStan

PHPStan supports error reporting in GitHub Actions, so it does not require problem matchers.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'tools:phpstan-name:Run PHPStanrun:phpstan analyse src

Psalm

Psalm supports error reporting in GitHub Actions with an output formatgithub.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'tools:psalm-name:Run Psalmrun:psalm --output-format=github

Tools with checkstyle support

For tools that supportcheckstyle reporting likephpstan,psalm,php-cs-fixer andphpcs you can usecs2pr to annotate your code.
For examples refer to thecs2pr documentation.

Here is an example withphpcs.

-name:Setup PHPuses:shivammathur/setup-php@v2with:php-version:'8.5'tools:cs2pr, phpcs-name:Run phpcsrun:phpcs -q --report=checkstyle src | cs2pr

Examples

Examples of usingsetup-php with various PHP frameworks and packages.

Framework/PackageRuns onWorkflow
BlackfiremacOS,ubuntu andwindowsblackfire.yml
Blackfire PlayermacOS,ubuntu andwindowsblackfire-player.yml
CakePHP withMySQL andRedisubuntucakephp-mysql.yml
CakePHP withPostgreSQL andRedisubuntucakephp-postgres.yml
CakePHP without servicesmacOS,ubuntu andwindowscakephp.yml
CodeIgnitermacOS,ubuntu andwindowscodeigniter.yml
Laminas MVCmacOS,ubuntu andwindowslaminas-mvc.yml
Laravel withMySQL andRedisubuntularavel-mysql.yml
Laravel withPostgreSQL andRedisubuntularavel-postgres.yml
Laravel without servicesmacOS,ubuntu andwindowslaravel.yml
Lumen withMySQL andRedisubuntulumen-mysql.yml
Lumen withPostgreSQL andRedisubuntulumen-postgres.yml
Lumen without servicesmacOS,ubuntu andwindowslumen.yml
Phalcon withMySQLubuntuphalcon-mysql.yml
Phalcon withPostgreSQLubuntuphalcon-postgres.yml
Roots/bedrockubuntubedrock.yml
Roots/sageubuntusage.yml
Slim FrameworkmacOS,ubuntu andwindowsslim-framework.yml
Symfony withMySQLubuntusymfony-mysql.yml
Symfony withPostgreSQLubuntusymfony-postgres.yml
Symfony without servicesmacOS,ubuntu andwindowssymfony.yml
Yii2 Starter Kit withMySQLubuntuyii2-mysql.yml
Yii2 Starter Kit withPostgreSQLubuntuyii2-postgres.yml

🔖 Versioning

  • Use thev2 tag assetup-php version. It is a rolling tag and is synced with the latest minor and patch releases. Withv2 you automatically get the bug fixes, security patches, new features and support for latest PHP releases.
  • Semantic release versions can also be used. It is recommended touse dependabot 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.
  • For debugging any issuesverbose tag can be used temporarily. It outputs all the logs and is also synced with the latest releases.
  • It is highly discouraged to use themain branch as version, it might break your workflow after major releases as they have breaking changes.
  • If you are using thev1 tag or a1.x.y version, you shouldswitch to v2 asv1 is not supported anymore.

📜 License

  • The scripts and documentation in this project are under theMIT License.
  • This project has multipledependencies. Their licenses can be found in their respective repositories.
  • The logo forsetup-php is a derivative work ofphp.net logo and is licensed under theCC BY-SA 4.0 License.

👍 Contributions

Contributions are welcome!

  • SeeContributor's Guide before you start.
  • If you face any issues or want to suggest a feature/improvement, start a discussionhere.

Contributors ofsetup-php and other related projects

Contributors of setup-php and related projects

💖 Support This Project

These companies generously provide setup-php their products and services to aid in the development of this project.

JetBrainsJetBrains          CloudflareCloudflare          Mac StadiumMac Stadium          DigitaloceanDigitalocean

Many users and organizations support setup-php viaGitHub Sponsors.

Sponsor shivammathur

  • If you use setup-php, please consider starring the project and share it.
  • If you blog, please share your experience of usingsetup-php.
  • Pleasereach out if you have any questions about sponsoring setup-php.

📦 Dependencies

📑 Further Reading

About

GitHub action to set up PHP with extensions, php.ini configuration, coverage drivers, and various tools.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

[8]ページ先頭

©2009-2025 Movatter.jp