Skip to content

Commit 4cec19f

Browse files
committed
Add comprehensive buildpack documentation
Add 80K of comprehensive documentation covering architecture, features, migration, and service binding patterns for both end users and developers/maintainers. Documentation Structure: - docs/USER_GUIDE.md (15K, 865 lines) - Complete end-user guide - docs/FEATURES.md (11K, 696 lines) - Developer reference with test coverage - docs/BUILDPACK_COMPARISON.md (12K) - Cross-buildpack architectural analysis - docs/VCAP_SERVICES_USAGE.md (12K) - Service binding patterns and best practices - docs/REWRITE_MIGRATION.md (27K) - v4.x to v5.x migration guide - docs/README.md (7K) - Navigation hub with best practices USER_GUIDE.md (For End Users): - Getting started (deploy in 2 commands) - Web server configuration (Apache, Nginx, FPM-only) - PHP configuration (versions, ini files, FPM pools) - PHP extensions installation - Composer and dependency management - APM integration (NewRelic, AppDynamics, Dynatrace) - Session storage (Redis, Memcached) - Framework guides (Laravel, CakePHP, Symfony, Laminas) - Advanced features (multi-buildpack, preprocess commands) - Troubleshooting section FEATURES.md (For Developers/Maintainers): - 30+ features with explicit integration test references - Test locations (file:line numbers) - Fixture paths for each feature - Implementation details and code snippets - Test coverage analysis matrix - Identification of features needing explicit tests - Cross-references to integration tests BUILDPACK_COMPARISON.md: - Proves PHP v5.x follows same patterns as Go, Java, Ruby, Python buildpacks - Documents VCAP_SERVICES availability during staging - Explains why v4.x runtime rewrite was PHP-unique, not a CF standard - Shows alignment with Cloud Foundry buildpack ecosystem VCAP_SERVICES_USAGE.md: - Clarifies VCAP_SERVICES IS available during staging (for extensions and Go code) - Documents that @{VCAP_SERVICES} config file placeholders are not supported - Provides service binding patterns and examples - Migration strategies from v4.x - Best practices and anti-patterns REWRITE_MIGRATION.md: - Comprehensive v4.x to v5.x migration guide - Breaking changes in rewrite system - Placeholder syntax changes - User-provided config handling - Corrects misconceptions about VCAP_SERVICES availability Key Documentation Insights: - VCAP_SERVICES IS available during staging in Go code (not just runtime) - PHP v5.x aligns with all other CF buildpacks (Go, Java, Ruby, Python) - v4.x runtime rewrite was PHP-unique, removed for CF standards alignment - 95%+ test coverage verification for documented features - Separate docs for end users vs developers/maintainers The documentation demonstrates comprehensive feature coverage and provides clear guidance for both buildpack users and maintainers.
1 parent a32677b commit 4cec19f

File tree

7 files changed

+3600
-12
lines changed

7 files changed

+3600
-12
lines changed

README.md

Lines changed: 168 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ A buildpack to deploy PHP applications to Cloud Foundry based systems, such as a
88

99
Official buildpack documentation can be found here: [php buildpack docs](http://docs.cloudfoundry.org/buildpacks/php/index.html).
1010

11+
**Developer Documentation:**
12+
- [docs/](docs/) - Architecture and implementation guides
13+
- [User Guide](docs/USER_GUIDE.md) - Complete user guide for all buildpack features
14+
- [Features Reference](docs/FEATURES.md) - Developer reference with test coverage verification
15+
- [VCAP_SERVICES Usage](docs/VCAP_SERVICES_USAGE.md) - Service binding patterns
16+
- [Buildpack Comparison](docs/BUILDPACK_COMPARISON.md) - Alignment with CF standards
17+
- [Migration Guide](docs/REWRITE_MIGRATION.md) - v4.x to v5.x migration
18+
1119
### Building the Buildpack
1220

1321
To build this buildpack, run the following commands from the buildpack's directory:
@@ -84,7 +92,7 @@ More information can be found on Github [switchblade](https://github.com/cloudfo
8492
8593
The project is broken down into the following directories:
8694
87-
- `bin/` - Executable shell scripts for buildpack lifecycle: `detect`, `supply`, `finalize`, `release`, `start`, `rewrite`
95+
- `bin/` - Executable shell scripts for buildpack lifecycle: `detect`, `supply`, `finalize`, `release`, `start`
8896
- `src/php/` - Go source code for the buildpack
8997
- `detect/` - Detection logic
9098
- `supply/` - Dependency installation (PHP, HTTPD, Nginx)
@@ -118,27 +126,76 @@ This buildpack uses Cloud Foundry's [libbuildpack](https://github.com/cloudfound
118126
3. **Finalize** (`bin/finalize``src/php/finalize/`) - Final configuration:
119127
- Configures web server (HTTPD or Nginx)
120128
- Sets up PHP and PHP-FPM configuration
121-
- Copies rewrite and start binaries to `.bp/bin/`
129+
- Copies start binary to `.bp/bin/`
130+
- Processes configuration files to replace build-time placeholders with runtime values
122131
- Generates preprocess scripts that will run at startup
123132
- Prepares runtime environment
124133

125134
4. **Release** (`bin/release``src/php/release/`) - Provides process types and metadata
126135

127136
#### Runtime Phases
128137

129-
5. **Rewrite** (`bin/rewrite``src/php/rewrite/cli/`) - Configuration templating at runtime:
130-
- Called during application startup (before services start)
131-
- Replaces template patterns in configuration files with runtime environment variables
132-
- Supports patterns: `@{VAR}`, `#{VAR}`, `@VAR@`, `#VAR`
133-
- Allows configuration to adapt to the actual runtime environment (ports, paths, etc.)
134-
- Rewrites PHP, PHP-FPM, and web server configs
135-
136-
6. **Start** (`bin/start``src/php/start/cli/`) - Process management:
137-
- Runs preprocess commands (including rewrite operations)
138+
5. **Start** (`bin/start``src/php/start/cli/`) - Process management:
139+
- Runs preprocess commands
140+
- Handles dynamic runtime variables (PORT, TMPDIR) via sed replacement
138141
- Launches all configured services (PHP-FPM, web server, etc.) from `.procs` file
139142
- Monitors all processes
140143
- If any process exits, terminates all others and restarts the application
141144

145+
### Configuration Placeholders
146+
147+
The buildpack uses a two-tier placeholder system for configuration files:
148+
149+
#### Build-Time Placeholders (`@{VAR}`)
150+
151+
These placeholders are replaced during the **finalize phase** (staging/build time) with known values:
152+
153+
- `@{HOME}` - Replaced with dependency or app directory path
154+
- `@{DEPS_DIR}` - Replaced with `/home/vcap/deps`
155+
- `@{WEBDIR}` - Replaced with web document root (default: `htdocs`)
156+
- `@{LIBDIR}` - Replaced with library directory (default: `lib`)
157+
- `@{PHP_FPM_LISTEN}` - Replaced with PHP-FPM socket/TCP address
158+
- `@{TMPDIR}` - Converted to `${TMPDIR}` for runtime expansion
159+
- `@{PHP_EXTENSIONS}` - Replaced with extension directives
160+
- `@{ZEND_EXTENSIONS}` - Replaced with Zend extension directives
161+
- `@{PHP_FPM_CONF_INCLUDE}` - Replaced with fpm.d include directive
162+
163+
**Example** (php.ini):
164+
```ini
165+
; Before finalize:
166+
extension_dir = "@{HOME}/php/lib/php/extensions"
167+
include_path = "@{HOME}/@{LIBDIR}"
168+
169+
; After finalize:
170+
extension_dir = "/home/vcap/deps/0/php/lib/php/extensions"
171+
include_path = "/home/vcap/deps/0/lib"
172+
```
173+
174+
#### Runtime Variables (`${VAR}`)
175+
176+
These are standard environment variables expanded at **runtime**:
177+
178+
- `${PORT}` - HTTP port assigned by Cloud Foundry (dynamic)
179+
- `${TMPDIR}` - Temporary directory (can be customized)
180+
- `${HOME}` - Application directory
181+
- `${HTTPD_SERVER_ADMIN}` - Apache admin email
182+
183+
**Supported by:**
184+
- **Apache HTTPD** - Native variable interpolation for any `${VAR}`
185+
- **Bash scripts** - Standard shell expansion for any `${VAR}`
186+
- **Nginx/PHP configs** - Only `${PORT}` and `${TMPDIR}` via sed replacement
187+
188+
**Example** (httpd.conf):
189+
```apache
190+
Listen ${PORT} # Expanded by Apache at runtime
191+
ServerRoot "${HOME}/httpd" # Expanded by Apache at runtime
192+
DocumentRoot "${HOME}/htdocs" # Expanded by Apache at runtime
193+
```
194+
195+
**Note:** Custom placeholders are **not supported**. To use custom configuration values, either:
196+
- Use environment variables with `${VAR}` syntax (works with Apache/bash)
197+
- Set values directly in your code instead of using placeholders
198+
142199
### Extensions
143200

144201
The buildpack includes several built-in extensions written in Go:
@@ -175,9 +232,108 @@ type Extension interface {
175232

176233
For examples, see the built-in extensions in `src/php/extensions/`.
177234

178-
**Note:** Custom user extensions from `.extensions/` directory are not currently supported in the Go-based buildpack. This feature may be added in a future release.
235+
### User Extensions
236+
237+
The buildpack supports user-defined extensions through the `.extensions/` directory. This allows you to add custom startup commands, environment variables, and services without modifying the buildpack itself.
238+
239+
#### Creating a User Extension
240+
241+
Create a directory `.extensions/<name>/` in your application with an `extension.json` file:
242+
243+
```
244+
myapp/
245+
├── .extensions/
246+
│ └── myext/
247+
│ └── extension.json
248+
├── index.php
249+
└── .bp-config/
250+
└── options.json
251+
```
252+
253+
#### extension.json Format
254+
255+
```json
256+
{
257+
"name": "my-custom-extension",
258+
"preprocess_commands": [
259+
"echo 'Running setup'",
260+
["./bin/setup.sh", "arg1", "arg2"]
261+
],
262+
"service_commands": {
263+
"worker": "php worker.php --daemon"
264+
},
265+
"service_environment": {
266+
"MY_VAR": "my_value",
267+
"ANOTHER_VAR": "another_value"
268+
}
269+
}
270+
```
271+
272+
**Fields:**
273+
274+
- `name` - Extension identifier (defaults to directory name)
275+
- `preprocess_commands` - Commands to run at container startup before PHP-FPM starts. Each command can be a string or array of arguments.
276+
- `service_commands` - Map of long-running background services (name → command)
277+
- `service_environment` - Environment variables to set for services
278+
279+
### Additional Configuration Options
280+
281+
#### ADDITIONAL_PREPROCESS_CMDS
282+
283+
Run custom commands at container startup before PHP-FPM starts. Useful for migrations, cache warming, or other initialization tasks.
284+
285+
**Configuration (`.bp-config/options.json`):**
286+
287+
```json
288+
{
289+
"ADDITIONAL_PREPROCESS_CMDS": [
290+
"php artisan migrate --force",
291+
"php artisan config:cache",
292+
["./bin/setup.sh", "arg1", "arg2"]
293+
]
294+
}
295+
```
296+
297+
Commands can be:
298+
- A string: `"echo hello"` - runs as a single command
299+
- An array: `["script.sh", "arg1"]` - arguments joined with spaces
179300

301+
#### Standalone PHP Mode (APP_START_CMD)
302+
303+
For CLI/worker applications that don't need a web server or PHP-FPM, you can run a PHP script directly.
304+
305+
**Configuration (`.bp-config/options.json`):**
306+
307+
```json
308+
{
309+
"WEB_SERVER": "none",
310+
"APP_START_CMD": "worker.php"
311+
}
312+
```
313+
314+
**Auto-detection:** If `WEB_SERVER` is set to `"none"` and `APP_START_CMD` is not specified, the buildpack searches for these entry point files:
315+
- `app.php`
316+
- `main.php`
317+
- `run.php`
318+
- `start.php`
319+
320+
If none are found, it defaults to running PHP-FPM only (for custom proxy setups).
321+
322+
**Example worker script:**
323+
324+
```php
325+
<?php
326+
// worker.php - Long-running background worker
327+
echo "Worker started\n";
328+
329+
while (true) {
330+
// Process jobs from queue
331+
processNextJob();
332+
sleep(1);
333+
}
334+
```
180335
336+
**Note:** Standalone apps on Cloud Foundry may need special health check configuration since they don't have an HTTP endpoint.
181337

182338
### Help and Support
183339

0 commit comments

Comments
 (0)