-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathgsg-php-composer.html.md.erb
91 lines (60 loc) · 7.19 KB
/
gsg-php-composer.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---
title: Composer
owner: Buildpacks
---
Composer is activated when you supply a `composer.json` or `composer.lock` file.
A `composer.lock` is not required, but is strongly recommended for consistent deployments.
You can require dependencies for packages and extensions. Extensions must be prefixed with the standard `ext-`. If you reference an extension that is available to the buildpack, it automatically is installed. See the main [README] for a list of supported extensions.
The buildpack uses the version of PHP specified in your `composer.json` or `composer.lock` file. Composer settings override the version set in the `options.json` file.
The PHP buildpack supports a subset of the version formats supported by Composer. The buildpack supported formats are:
| Example | Expected Version |
------------- | ----------------------------------|
| 5.3.* | latest 5.4.x release (5.3 is not supported) |
| >=5.3 | latest 5.4.x release (5.3 is not supported) |
| 5.4.* | latest 5.4.x release |
| >=5.4 | latest 5.4.x release |
| 5.5.* | latest 5.5.x release |
| >=5.5 | latest 5.5.x release |
| 5.4.x | specific 5.4.x release that is listed |
| 5.5.x | specific 5.5.x release that is listed |
## <a id="configuration"></a> Configuration
The buildpack runs with a set of default values for Composer.
You can adjust these values by adding a `.bp-config/options.json` file to your application and setting any of the following values in it.
| Variable | Explanation |
| ---------------------------- | ----------------------------------------------------- |
| COMPOSER_VERSION | The version of Composer to use. It defaults to the latest bundled with the buildpack. |
| COMPOSER_INSTALL_OPTIONS | A list of options that should be passed to `composer install`. This defaults to `["--no-interaction", "--no-dev", "--no-progress"]`. The `--no-progress` option must be used due to the way the buildpack calls Composer. |
| COMPOSER_VENDOR_DIR | Allows you to override the default value used by the buildpack. This is passed through to Composer and instructs it where to create the `vendor` directory. Defaults to `{BUILD_DIR}/{LIBDIR}/vendor`. |
| COMPOSER_BIN_DIR | Allows you to override the default value used by the buildpack. This is passed through to Composer and instructs it where to place executables from packages. Defaults to `{BUILD_DIR}/php/bin`. |
| COMPOSER_CACHE_DIR | Allows you to override the default value used by the buildpack. This is passed through to Composer and instructs it where to place its cache files. Generally you should not change this value. The default is `{CACHE_DIR}/composer` which is a subdirectory of the cache folder passed in to the buildpack. Composer cache files are restored on subsequent application pushes. |
By default, the PHP buildpack uses the `composer.json` and `composer.lock` files that reside inside the root directory, or in the directory specified as `WEBDIR` in your `options.json`. If you have composer files inside your app, but not in the default directories, use a `COMPOSER_PATH` environment variable for your app to specify this custom location, relative to the app root directory. Note, that the `composer.json` and `composer.lock` files must be in the same directory.
## <a id="github-api-limits"></a> GitHub API request limits
Composer uses GitHub's API to retrieve zip files for installation into the application folder. If you do not vendor dependencies before pushing an app, Composer can fetch dependencies during staging using the GitHub API.
GitHub's API is request-limited. If you reach your daily allowance of API requests (typically 60), GitHub's API returns a `403` error and staging fails.
There are two ways to avoid the request limit:
- Vendor dependencies before pushing your application.
- Supply a GitHub OAuth API token.
### Vendor dependencies
For vendor dependencies, you must run `composer install` before you push your application. You might also need to configure `COMPOSER_VENDOR_DIR` to "vendor".
### Supply a GitHub token
Composer can use [GitHub API OAuth tokens](https://help.github.com/articles/creating-an-access-token-for-command-line-use/), which increase your request limit, typically to 5000 per day.
During staging, the buildpack looks for this token in the environment variable `COMPOSER_GITHUB_OAUTH_TOKEN`. If you supply a valid token, Composer uses it. This mechanism does not work if the token is invalid.
To supply the token, use one of the following methods:
- Run:
```
cf set-env YOUR_APP_NAME COMPOSER_GITHUB_OAUTH_TOKEN "OAUTH_TOKEN_VALUE"
```
- Add the token to the `env` block of your application manifest.
## <a id="staging-environment"></a> Buildpack staging environment
Composer runs in the buildpack staging environment. Variables set with `cf set-env` or with [a manifest.yml 'env' block](../../devguide/deploy-apps/manifest.html#env-block) are visible to Composer.
For example:
<pre class="terminal">
$ cf push a_symfony_app --no-start
$ cf set-env a_symfony_app SYMFONY_ENV "prod"
$ cf start a_symfony_app
</pre>
In this example, `a_symfony_app` is supplied with an environment variable, `SYMFONY_ENV`, which is visible to Composer and any scripts started by Composer.
### Non-configurable environment variables
User-assigned environment variables are applied to staging and runtime. Unfortunately, `LD_LIBRARY_PATH` and `PHPRC` must be different for staging and runtime. The buildpack takes care of setting these variables, which means user values for these variables are ignored.
[Composer]:https://getcomposer.org
[README]:https://github.com/cloudfoundry/php-buildpack#supported-software