Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP PIE for installing extensions to docs #2521

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions php/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,23 @@ See also ["Dockerizing Compiled Software"](https://tianon.xyz/post/2017/12/26/do

Some extensions are compiled by default. This depends on the PHP version you are using. Run `php -m` in the container to get a list for your specific version.

### PIE extensions

The latest recommended way of installing PHP extensions is through [PIE](https://github.com/php/pie). To install a PIE-compatible extension, use `pie install` to download, compile and enable it.

```dockerfile
FROM %%IMAGE%%:8.2-cli

# Install PIE here (see https://github.com/php/pie/blob/main/docs/usage.md)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably do:

Suggested change
# Install PIE here (see https://github.com/php/pie/blob/main/docs/usage.md)
# Install PIE here (see https://github.com/php/pie/blob/main/docs/usage.md)
COPY --from=ghcr.io/php/pie:bin /pie /usr/bin/pie

perhaps? to demo a real working example...

Copy link

@asgrim asgrim Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a working example:

FROM php:8.4-cli                                                                                                                            
                                                                                                                                            
RUN apt-get update \
    && apt-get install -y libzip-dev zip \
    && docker-php-ext-install zip

COPY --from=ghcr.io/php/pie:bin /pie /usr/bin/pie

RUN pie install xdebug/xdebug

Ironically, you can't use PIE to install the zip extension as it depends on it (see php/pie#168)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for looking into this so quickly! I too do prefer the COPY --from=ghcr.io/php/pie:bin call for installing this. Given that multi-stage builds are officially supported nowadays this probably should be fine. Given that is an example and official upstream source referencing a non-official image is probably also fine, but I'll wait for maintainer feedback on that.

I also just figured the zip extension requirement makes it somewhat cumbersome to use when paired with Docker compared to PECL working out of the box. But to solve that it seems that php/pie#133 probably would also need to be addressed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a working example:

The zip binary package is not required there. It should also clean up after itself. I previously provided a full example following the best practices in: php/pie#122 (comment)


RUN pie install phpredis/phpredis:^6.1 \
&& pie install xdebug/xdebug:^3.4
```

### PECL extensions

⚠️ Note: Installation of PEAR and thus also PECL with PHP is deprecated and thus subject to removal in a future PHP version. See also https://github.com/php/php-src/commit/e93d6d97aab7a5de1f7b8dc750ca9d08214de8c4.

Some extensions are not provided with the PHP source, but are instead available through [PECL](https://pecl.php.net/). To install a PECL extension, use `pecl install` to download and compile it, then use `docker-php-ext-enable` to enable it:

```dockerfile
Expand Down
Loading