PHP Buildpack

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

To build a sample app locally with this CNB using the pack CLI, run

git clone https://github.com/paketo-buildpacks/samples
cd samples/php/webserver
pack build my-app --buildpack gcr.io/paketo-buildpacks/php --builder paketobuildpacks/builder:full
copy to clipboard
Copied!

See samples for how to run the app.

Supported dependencies

The PHP Paketo Buildpack supports several versions of PHP. For more details on the specific versions supported in a given buildpack version, see the release notes.

Specifying a PHP Version

The PHP Dist 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.*
copy to clipboard
Copied!

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"
  }
}
copy to clipboard
Copied!

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"]
copy to clipboard
Copied!

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
copy to clipboard
Copied!

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
copy to clipboard
Copied!

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.

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

Last modified: October 16, 2020