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
Copied!
See samples for how to run the app.
NOTE: The Paketo Full builder is required because PHP relies on operating system libraries only present in the Full builder.
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.
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
.
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.*
Copied!
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" } }
Copied!
If your app has a composer.lock
file, the buildpack will use
the php version defined there.
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"]
Copied!
The PHP buildpack supports the use of 3 different web servers:
You can configure the webserver using buildpack.yml
as follows:
php: # options are: php-server, httpd, nginx. default: php-server webserver: php-server
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
Copied!
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.
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.
httpd
buildpacklaunch
httpd
buildpacklaunch
php-dist
buildpackbuild
and launch
php-dist
buildpackbuild
and launch
php-dist
buildpackbuild
and launch
php-dist
buildpackbuild
and launch
php-dist
buildpackbuild
and launch
php-web
buildpackbuild
and launch
<APP-ROOT>/.php.ini.d
Last modified: January 12, 2021