Skip to content

Commit 4207aea

Browse files
committed
Document .ini file extension loading feature
Add user-facing and technical documentation for the new feature that allows loading PHP extensions via .ini files in .bp-config/php/php.ini.d. README.md changes: - Add 'PHP Extension Configuration' section - Explain .ini file syntax with examples - Compare with .bp-config/options.json alternative - Document built-in vs PECL extension categories - Clarify which extensions require explicit loading ARCHITECTURE.md changes: - Add detailed implementation documentation - Document extension parsing flow in both supply and composer phases - Explain rationale for parsing approach (no duplicate loading) - Include extension loading flow diagram - Reference key source files and line numbers - Document composer build-time PHP installation architecture
1 parent 7c4cadc commit 4207aea

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed

ARCHITECTURE.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,110 @@ func (c *ComposerExtension) Supply(stager libbuildpack.Stager) error {
485485
}
486486
```
487487

488+
### PHP Extension Configuration
489+
490+
The buildpack supports two methods for specifying PHP extensions to load:
491+
492+
#### Method 1: .ini Files (Standard PHP Format)
493+
494+
Users can create `.ini` files in `.bp-config/php/php.ini.d/` with standard PHP extension directives:
495+
496+
```ini
497+
[PHP]
498+
extension=apcu.so
499+
extension=redis.so
500+
zend_extension=opcache.so
501+
```
502+
503+
**Implementation Details:**
504+
505+
During both the **supply phase** (`src/php/supply/supply.go`) and **composer phase** (`src/php/extensions/composer/composer.go`), the buildpack:
506+
507+
1. Walks the `.bp-config/php/php.ini.d/` directory
508+
2. Parses all `.ini` files looking for `extension=` and `zend_extension=` directives
509+
3. Extracts extension names (stripping `.so` suffix and quotes)
510+
4. Adds these extensions to the buildpack context's `PHP_EXTENSIONS` and `ZEND_EXTENSIONS` lists
511+
5. The buildpack's normal extension configuration mechanism handles loading them
512+
513+
**Key Functions:**
514+
515+
- `loadUserExtensions()` in `src/php/supply/supply.go` (lines 850-945)
516+
- `loadUserExtensions()` in `src/php/extensions/composer/composer.go` (lines 1254-1341)
517+
518+
**Why This Approach:**
519+
520+
- **No duplicate loading**: Extensions are only configured once through the buildpack mechanism
521+
- **Consistent**: Works the same way as extensions specified in `.bp-config/options.json`
522+
- **Build-time and runtime**: Extensions are available during `composer install` and at application runtime
523+
- **Familiar syntax**: PHP developers already know `.ini` file format
524+
525+
#### Method 2: options.json (Buildpack-Specific Format)
526+
527+
Alternatively, users can specify extensions in `.bp-config/options.json`:
528+
529+
```json
530+
{
531+
"PHP_EXTENSIONS": ["apcu", "redis"],
532+
"ZEND_EXTENSIONS": ["opcache"]
533+
}
534+
```
535+
536+
Both methods produce the same result and can be used interchangeably.
537+
538+
#### Extension Types
539+
540+
PHP extensions fall into two categories (defined in `manifest.yml`):
541+
542+
1. **Built-in Extensions** - Have empty `version:` field, compiled into PHP binary
543+
- Examples: `bz2`, `curl`, `fileinfo`, `gettext`, `openssl`, `sockets`, `zip`
544+
- Always available, no explicit loading required
545+
546+
2. **PECL Extensions** - Have version numbers (e.g., `5.1.23`), distributed separately
547+
- Examples: `apcu`, `redis`, `mongodb`, `imagick`, `memcached`, `opcache`
548+
- Require explicit loading via `.ini` files or `options.json`
549+
550+
#### Composer Build-Time PHP Installation
551+
552+
The composer extension creates a separate PHP installation specifically for running `composer install`:
553+
554+
**Location:** `BUILD_DIR/php/` (temporary, not in final application)
555+
556+
**Why separate?**
557+
558+
- Composer may have different PHP version requirements than the runtime
559+
- Allows composer to run with extensions needed for dependency installation
560+
- Isolated from runtime PHP configuration
561+
562+
**Extension Loading Flow:**
563+
564+
```
565+
1. Supply Phase (supply.go)
566+
├─► loadUserExtensions()
567+
│ └─► Parse .bp-config/php/php.ini.d/*.ini
568+
│ └─► Add to ctx.PHP_EXTENSIONS
569+
570+
└─► Install runtime PHP with extensions
571+
572+
2. Composer Phase (composer.go)
573+
├─► loadUserExtensions()
574+
│ └─► Parse .bp-config/php/php.ini.d/*.ini
575+
│ └─► Add to ctx.PHP_EXTENSIONS
576+
577+
├─► Install temporary PHP for composer
578+
│ └─► Configure with user extensions
579+
580+
├─► setupPHPConfig()
581+
│ └─► Generate php.ini with extension_dir
582+
583+
└─► Run: php composer.phar install
584+
└─► Extensions now available during install
585+
```
586+
587+
**Key Files:**
588+
589+
- `src/php/extensions/composer/composer.go` - Main composer extension logic
590+
- `src/php/supply/supply.go` - Runtime PHP installation and extension configuration
591+
488592
## Comparison with Other Buildpacks
489593

490594
### Go Buildpack

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,48 @@ This buildpack uses Cloud Foundry's [libbuildpack](https://github.com/cloudfound
139139
- Monitors all processes
140140
- If any process exits, terminates all others and restarts the application
141141

142+
### PHP Extension Configuration
143+
144+
The buildpack supports loading PHP extensions using standard `.ini` file syntax. This allows extensions to be available during both build-time (composer install) and runtime.
145+
146+
#### Loading Extensions via .ini Files
147+
148+
Create `.ini` files in `.bp-config/php/php.ini.d/` directory with standard PHP extension directives:
149+
150+
**Example: `.bp-config/php/php.ini.d/custom.ini`**
151+
```ini
152+
[PHP]
153+
extension=apcu.so
154+
extension=redis.so
155+
zend_extension=opcache.so
156+
```
157+
158+
These extensions will be loaded during:
159+
- **Build-time**: Available during `composer install` execution (if your dependencies require specific extensions)
160+
- **Runtime**: Available when your application runs
161+
162+
**Alternative Method:** You can also specify extensions in `.bp-config/options.json`:
163+
```json
164+
{
165+
"PHP_EXTENSIONS": ["apcu", "redis"],
166+
"ZEND_EXTENSIONS": ["opcache"]
167+
}
168+
```
169+
170+
Both methods are equivalent and produce the same result. Use whichever format you prefer.
171+
172+
#### Available Extensions
173+
174+
Check the `manifest.yml` file for all available extensions. Extensions fall into two categories:
175+
176+
1. **Built-in Extensions** (no version number) - Compiled into PHP, always available:
177+
- `bz2`, `curl`, `fileinfo`, `gettext`, `openssl`, `sockets`, `zip`, etc.
178+
179+
2. **PECL Extensions** (with version numbers) - Require explicit loading:
180+
- `apcu`, `redis`, `mongodb`, `imagick`, `memcached`, `opcache`, etc.
181+
182+
Only PECL extensions need to be specified in `.ini` files or `options.json`. Built-in extensions are always available.
183+
142184
### Extensions
143185

144186
The buildpack includes several built-in extensions written in Go:

0 commit comments

Comments
 (0)