|
| 1 | +# PHP Buildpack Documentation |
| 2 | + |
| 3 | +This directory contains architectural documentation for the PHP buildpack v5.x. |
| 4 | + |
| 5 | +## Documentation Index |
| 6 | + |
| 7 | +### Features & User Guides |
| 8 | + |
| 9 | +- **[USER_GUIDE.md](USER_GUIDE.md)** - Complete user guide for all buildpack features |
| 10 | + - Getting started guide |
| 11 | + - Web server configuration (Apache HTTPD, Nginx, FPM-only) |
| 12 | + - PHP configuration and extensions |
| 13 | + - Composer and dependency management |
| 14 | + - APM integration (NewRelic, AppDynamics, Dynatrace) |
| 15 | + - Session storage (Redis, Memcached) |
| 16 | + - Framework guides (Laravel, CakePHP, Laminas, Symfony) |
| 17 | + - Advanced features and troubleshooting |
| 18 | + |
| 19 | +- **[FEATURES.md](FEATURES.md)** - Developer reference with test coverage verification |
| 20 | + - Feature list with test references |
| 21 | + - Integration test locations (file:line) |
| 22 | + - Fixture paths and examples |
| 23 | + - Implementation details |
| 24 | + - Test coverage analysis |
| 25 | + - Test gaps and notes |
| 26 | + |
| 27 | +### Architecture & Design |
| 28 | + |
| 29 | +- **[BUILDPACK_COMPARISON.md](BUILDPACK_COMPARISON.md)** - Comparison with other CF buildpacks (Go, Java, Ruby, Python) |
| 30 | + - Environment variable handling patterns |
| 31 | + - Configuration approaches |
| 32 | + - Service binding patterns |
| 33 | + - Profile.d script usage |
| 34 | + - Demonstrates PHP v5.x alignment with CF standards |
| 35 | + |
| 36 | +### Service Bindings |
| 37 | + |
| 38 | +- **[VCAP_SERVICES_USAGE.md](VCAP_SERVICES_USAGE.md)** - Comprehensive guide to VCAP_SERVICES |
| 39 | + - When VCAP_SERVICES is available (staging vs runtime) |
| 40 | + - How extensions use VCAP_SERVICES |
| 41 | + - Comparison with other buildpacks |
| 42 | + - Migration strategies from v4.x |
| 43 | + - Best practices and anti-patterns |
| 44 | + |
| 45 | +### Migration Guides |
| 46 | + |
| 47 | +- **[V4_V5_MIGRATION_GAP_ANALYSIS.md](V4_V5_MIGRATION_GAP_ANALYSIS.md)** - Comprehensive v4.x to v5.x feature comparison |
| 48 | + - Complete feature matrix (what's implemented, missing, or changed) |
| 49 | + - Missing features: `ADDITIONAL_PREPROCESS_CMDS`, `APP_START_CMD`, User Extensions |
| 50 | + - Implementation roadmap and priorities |
| 51 | + - Testing recommendations |
| 52 | + |
| 53 | +- **[REWRITE_MIGRATION.md](REWRITE_MIGRATION.md)** - v4.x to v5.x migration guide |
| 54 | + - Rewrite system changes |
| 55 | + - Breaking changes |
| 56 | + - Migration strategies |
| 57 | + - User-provided config handling |
| 58 | + |
| 59 | +## Quick Links |
| 60 | + |
| 61 | +### For Users |
| 62 | + |
| 63 | +**New to the buildpack?** |
| 64 | +1. Start with [USER_GUIDE.md](USER_GUIDE.md) to see what's supported |
| 65 | +2. Check examples for your web server (HTTPD, Nginx, etc.) |
| 66 | +3. Review [Best Practices](#best-practices) below |
| 67 | + |
| 68 | +**Migrating from v4.x?** |
| 69 | +1. **Start here:** [V4_V5_MIGRATION_GAP_ANALYSIS.md](V4_V5_MIGRATION_GAP_ANALYSIS.md) for complete feature comparison |
| 70 | +2. Read [REWRITE_MIGRATION.md](REWRITE_MIGRATION.md) for breaking changes |
| 71 | +3. Check [VCAP_SERVICES_USAGE.md](VCAP_SERVICES_USAGE.md) for service binding patterns |
| 72 | +4. Review feature parity in [USER_GUIDE.md](USER_GUIDE.md) |
| 73 | + |
| 74 | +**Using VCAP_SERVICES?** |
| 75 | +- See [VCAP_SERVICES_USAGE.md](VCAP_SERVICES_USAGE.md) for complete guide |
| 76 | +- Extensions automatically handle common services (NewRelic, Redis sessions) |
| 77 | +- Use profile.d scripts or application code for custom services |
| 78 | + |
| 79 | +### For Developers |
| 80 | + |
| 81 | +**Understanding the Architecture?** |
| 82 | +1. Read [BUILDPACK_COMPARISON.md](BUILDPACK_COMPARISON.md) to see how PHP v5.x aligns with other buildpacks |
| 83 | +2. Review [libbuildpack](https://github.com/cloudfoundry/libbuildpack) for shared library patterns |
| 84 | +3. Check source code organization in [../src/php/](../src/php/) |
| 85 | + |
| 86 | +**Creating Extensions?** |
| 87 | +- Extension framework in [../src/php/extensions/](../src/php/extensions/) |
| 88 | +- Context provides parsed VCAP_SERVICES and VCAP_APPLICATION |
| 89 | +- Write profile.d scripts for runtime environment setup |
| 90 | + |
| 91 | +## Best Practices |
| 92 | + |
| 93 | +### ✅ Recommended Patterns |
| 94 | + |
| 95 | +#### 1. Use Built-in Extensions |
| 96 | +```bash |
| 97 | +# NewRelic - just bind the service |
| 98 | +cf bind-service my-app my-newrelic |
| 99 | + |
| 100 | +# Redis Sessions - just bind the service |
| 101 | +cf bind-service my-app my-redis |
| 102 | +``` |
| 103 | + |
| 104 | +#### 2. Profile.d for Service Parsing |
| 105 | +```bash |
| 106 | +# .profile.d/parse-vcap.sh |
| 107 | +export DB_HOST=$(echo $VCAP_SERVICES | jq -r '.mysql[0].credentials.host') |
| 108 | +``` |
| 109 | + |
| 110 | +#### 3. Application Code for Database Credentials |
| 111 | +```php |
| 112 | +<?php |
| 113 | +$vcap = json_decode(getenv('VCAP_SERVICES'), true); |
| 114 | +$db = $vcap['mysql'][0]['credentials']; |
| 115 | +$pdo = new PDO("mysql:host={$db['host']};dbname={$db['name']}", ...); |
| 116 | +?> |
| 117 | +``` |
| 118 | + |
| 119 | +### ❌ Anti-Patterns |
| 120 | + |
| 121 | +#### 1. Trying to Use @{VCAP_SERVICES} Placeholders |
| 122 | +```ini |
| 123 | +# DOES NOT WORK - Not a supported placeholder |
| 124 | +[www] |
| 125 | +env[DB] = @{VCAP_SERVICES} |
| 126 | +``` |
| 127 | + |
| 128 | +#### 2. Expecting Config Changes Without Restaging |
| 129 | +```bash |
| 130 | +cf bind-service my-app new-db |
| 131 | +cf restart my-app # NOT SUFFICIENT if configs use build-time placeholders |
| 132 | +cf restage my-app # REQUIRED to pick up new service binding |
| 133 | +``` |
| 134 | + |
| 135 | +## Key Concepts |
| 136 | + |
| 137 | +### Build-Time vs Runtime |
| 138 | + |
| 139 | +**Build-Time (Staging):** |
| 140 | +- Placeholder replacement happens once |
| 141 | +- Config files written with known values |
| 142 | +- Extensions run and configure services |
| 143 | +- Profile.d scripts created |
| 144 | + |
| 145 | +**Runtime:** |
| 146 | +- Configs already processed |
| 147 | +- Profile.d scripts sourced |
| 148 | +- No config rewriting |
| 149 | +- Better performance and security |
| 150 | + |
| 151 | +### Placeholder Types |
| 152 | + |
| 153 | +**Build-Time Placeholders (`@{VAR}`):** |
| 154 | +- Replaced during finalize phase |
| 155 | +- Only predefined variables: `@{HOME}`, `@{WEBDIR}`, `@{LIBDIR}`, etc. |
| 156 | +- See [REWRITE_MIGRATION.md](REWRITE_MIGRATION.md) for complete list |
| 157 | + |
| 158 | +**Runtime Variables (`${VAR}`):** |
| 159 | +- Standard shell/environment variables |
| 160 | +- `${PORT}`, `${TMPDIR}`, `${VCAP_SERVICES}`, etc. |
| 161 | +- Expanded by shell or application code |
| 162 | + |
| 163 | +### Extension Context |
| 164 | + |
| 165 | +Extensions have access to: |
| 166 | +- `ctx.VcapServices` - Parsed VCAP_SERVICES |
| 167 | +- `ctx.VcapApplication` - Parsed VCAP_APPLICATION |
| 168 | +- `ctx.BuildDir`, `ctx.DepsDir` - Directory paths |
| 169 | +- `ctx.Env` - All environment variables |
| 170 | + |
| 171 | +Example: |
| 172 | +```go |
| 173 | +func (e *MyExtension) Install(installer extensions.Installer) error { |
| 174 | + // Access parsed VCAP_SERVICES |
| 175 | + for _, services := range e.ctx.VcapServices { |
| 176 | + for _, service := range services { |
| 177 | + // Configure based on service credentials |
| 178 | + } |
| 179 | + } |
| 180 | +} |
| 181 | +``` |
| 182 | + |
| 183 | +## Alignment with Cloud Foundry Standards |
| 184 | + |
| 185 | +PHP buildpack v5.x follows the **same patterns as all other CF buildpacks**: |
| 186 | + |
| 187 | +| Pattern | PHP v5.x | Go | Java | Ruby | Python | |
| 188 | +|---------|----------|-----|------|------|--------| |
| 189 | +| Read VCAP_SERVICES in code (staging) | ✅ | ✅ | ✅ | ✅ | ✅ | |
| 190 | +| Configure from service bindings | ✅ | ✅ | ✅ | ✅ | ✅ | |
| 191 | +| Write profile.d scripts | ✅ | ✅ | ✅ | ✅ | ✅ | |
| 192 | +| No runtime config rewriting | ✅ | ✅ | ✅ | ✅ | ✅ | |
| 193 | +| @{VCAP_SERVICES} placeholders | ❌ | ❌ | ❌ | ❌ | ❌ | |
| 194 | + |
| 195 | +**Key Insight:** The v4.x runtime rewrite was PHP-specific. Removing it brings alignment with CF ecosystem standards. |
| 196 | + |
| 197 | +## Additional Resources |
| 198 | + |
| 199 | +### Cloud Foundry Documentation |
| 200 | +- [VCAP_SERVICES](https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES) |
| 201 | +- [Buildpacks](https://docs.cloudfoundry.org/buildpacks/) |
| 202 | +- [Application Environment Variables](https://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html) |
| 203 | + |
| 204 | +### Related Buildpacks |
| 205 | +- [libbuildpack](https://github.com/cloudfoundry/libbuildpack) - Shared Go library |
| 206 | +- [Go Buildpack](https://github.com/cloudfoundry/go-buildpack) |
| 207 | +- [Java Buildpack](https://github.com/cloudfoundry/java-buildpack) |
| 208 | +- [Ruby Buildpack](https://github.com/cloudfoundry/ruby-buildpack) |
| 209 | +- [Python Buildpack](https://github.com/cloudfoundry/python-buildpack) |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## Contributing to Documentation |
| 214 | + |
| 215 | +When adding new documentation: |
| 216 | + |
| 217 | +1. **User-facing docs** → Update this README with links |
| 218 | +2. **Migration guides** → Add to [REWRITE_MIGRATION.md](REWRITE_MIGRATION.md) |
| 219 | +3. **Architecture docs** → Create new file in this directory |
| 220 | +4. **Code examples** → Include in relevant guide |
| 221 | + |
| 222 | +**Style Guidelines:** |
| 223 | +- Use clear section headers |
| 224 | +- Include code examples |
| 225 | +- Show both ✅ working and ❌ non-working patterns |
| 226 | +- Link to related documentation |
| 227 | +- Keep language simple and direct |
0 commit comments