Note: The Tanzu PHP Buildpack is currently in Beta

The Tanzu PHP Buildpack enables developers to build PHP-based applications.

Specifying a PHP Version

The PHP Dist Cloud Native Buildpack (CNB) allows you to specify a version of PHP to use during deployment. This version can be specified in a number of ways, including through buildpack.yml or composer.json files. When specifying a version of PHP, you must choose a version that is available within the buildpack.

The buildpack prioritizes the versions specified in each possible configuration location with the following precedence, from highest to lowest: buildpack.yml, composer.json.

Using buildpack.yml

To configure the buildpack to use PHP version when deploying your app, include the values like below in your buildpack.yml file. Any valid semver constraints are acceptable.

---
php:
  version: 7.2.*

Using composer.json

If your apps use composer, you can specify the PHP version your apps use during deployment by configuring the require field in the composer.json file. To configure the buildpack to use PHP v7.1 or greater when deploying your app, include the values below in your composer.json file:

{
  "require": {
    "php": ">=7.1"
  }
}

If your app has a composer.lock file, the buildpack will use the php version defined there.

Composer Configuration

The following options are configurable in the app's buildpack.yml

composer:
  # this allows you to specify a version constaint for composer
  # any valid semver constaints (e.g. 1.* and 1.10.*) are also acceptable
  version: 1.10.x

  # a list of command line install options for composer
  # default: ["--no-dev"]
  install_options: ["--no-dev"]

  # default: vendor
  vendor_directory: vendor

  # directory where composer.json can be found
  # default is app root
  json_path: composer

  # if included, will run `composer global` with with specified arguments
  install_global: ["list", "of", "install", "options"]

Web Server Configuration

The PHP buildpack supports the use of 3 different web servers:

  • PHP built-in Web Server
  • Apache HTTP Web Server
  • Nginx Web Server

You can configure the webserver using buildpack.yml as follows:

php:

 # options are: php-server, httpd, nginx. default: php-server
 webserver: php-server

If you're using httpd or nginx, a suitable httpd.conf or nginx.conf will be generated for you by the buildpack.

You can also provide additional configurations like follows:

php:

 # directory where web app code is stored
 # default: htdocs
 webdirectory: htdocs

 # directory where library code is stored
 # default: lib
 libdirectory: lib

 # cli script to use
 # no default
 script:

 # default: admin@localhost
 serveradmin: admin@localhost

Vendoring composer packages

If your php app that uses composer has a valid vendor directory, then the buildpack will not download those packages. It will instead use the the packages location in the vendor directory.

Access the Software Bill of Materials

The PHP buildpack includes support for the software bill of materials (SBOM). Check out the SBOM documentation for details on how to access the SBOM supplied by the buildpacks.

Buildpack-Set Environment Variables

The PHP CNB sets a number of environment variables during the build and launch phases of the app lifecycle. The sections below describe each environment variable and its impact on your app.

APP_ROOT

  • Set by: httpd buildpack
  • Phases: launch
  • Value: path of app source

SERVER_ROOT

  • Set by: httpd buildpack
  • Phases: launch
  • Value: path of the httpd installation

MIBDIRS

PATH

  • Set by: php-dist buildpack
  • Phases: build and launch
  • Value: path to the php executable

PHP_API

  • Set by: php-dist buildpack
  • Phases: build and launch
  • Value: internl api version (YYYYMMDD)

PHP_EXTENSION_DIR

  • Set by: php-dist buildpack
  • Phases: build and launch
  • Value: location of directory with dynamic libraries for extensions

PHP_HOME

  • Set by: php-dist buildpack
  • Phases: build and launch
  • Value: location of php installation
check-circle-line exclamation-circle-line close-line
Scroll to top icon