frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

WIP: Add extensions to php build in dockerfile

Open Pierstoval opened this issue 3 years ago • 14 comments

For now, doesn't compile on my machine, but I'll investigate further 👍

Pierstoval avatar Oct 16 '22 11:10 Pierstoval

Idea: we could adapt the Dockerfile of the official PHP image (ZTS version), so we could use the semi-official script they provide to add extra extensions. WDYT?

dunglas avatar Oct 17 '22 07:10 dunglas

I think it would be great to have the official PHP Image as a base image so we can use the extension installer of it, to adding third party extension easier (redis, imagick, vips, grpc, ..).

alexander-schranz avatar Oct 17 '22 07:10 alexander-schranz

The problem is that the official PHP images don't contain @dunglas's changes (yet), so unless we modify the source code manually as a hack from inside the dockerfile, it won't be possible yet. And the official PHP dockerfile is downloading a tar file from php.net, not using the git repo, and to my knowledge it's not possible to "hack into" an existing dockerfile.

I'm not sure we can't do anything with the official image unless @dunglas's customized php-src can be merged.

Or we should copy/paste the contents from the docker-php-* scripts there, but I'm not sure how tied to the Dockerfile they are 😕

Pierstoval avatar Oct 17 '22 08:10 Pierstoval

We could copy/paste/adapt the official Dockerfile to use my temporary fork of PHP. The main benefit would be that we'll keep compatibility with all existing docs and scripts regarding PHP and Docker.

Using the vanilla images will not be possible soon because we also need a Go build chain (but we should build the Go app in a dedicated stage to not ship the go tool chain in the final image).

dunglas avatar Oct 17 '22 09:10 dunglas

Is it possible that without these extensions we cannot use mysql doctrine via frankenphp sf?

MakFly avatar Oct 17 '22 09:10 MakFly

Because i add a container mysql for use a database mysql but it doesn't work .

`In ExceptionConverter.php line 117:

An exception occurred in the driver: could not find driver

In Exception.php line 28:

could not find driver

In Driver.php line 27:

could not find driver `

MakFly avatar Oct 17 '22 09:10 MakFly

@MakFly for now, since PHP is built from source in FrankenPHP, it also needs to build the different PHP extensions, such as pdo-mysql in your case. Since building the extensions needs more work, it is an ongoing process :)

@dunglas the most problematic thing I see is that this means that FrankenPHP needs 2 different steps to be built: build PHP frmo source, and then build FrankenPHP that bundles it. The end-user willing to use extensions would have to plug inbetween the 2, and I don't see how that would be possible in a userland Dockerfile

Pierstoval avatar Oct 17 '22 09:10 Pierstoval

https://github.com/mlocati/docker-php-extension-installer/blob/78e9e45c4c3c83867ff2145e274841237a85de05/install-php-extensions#L15 -- looks like you only need to create compatible binaries/scripts for using this script, if you wanted to go that way.

Official versions of what those scripts do can be found here:

https://github.com/docker-library/php/tree/master/8.2-rc/bullseye/zts

withinboredom avatar Oct 17 '22 10:10 withinboredom

FWIW, I started on a multi-stage build for this, but I can't get the docker image to build locally:

frankenphp.c: At top level:
#24 27.48 frankenphp.c:16:10: fatal error: C-Thread-Pool/thpool.h: No such file or directory
#24 27.48    16 | #include "C-Thread-Pool/thpool.h"
#24 27.48       |          ^~~~~~~~~~~~~~~~~~~~~~~~
#24 27.48 compilation terminated.

withinboredom avatar Oct 17 '22 10:10 withinboredom

@withinboredom to git submodules need to be installed not sure what the correct command is for this but: git submodule update --init --recursive worked for me, before running the docker build command.

alexander-schranz avatar Oct 17 '22 10:10 alexander-schranz

@Pierstoval

And the official PHP dockerfile is downloading a tar file from php.net, not using the git repo, and to my knowledge it's not possible to "hack into" an existing dockerfile.

If its only about the tar we can also get a tar from github.

Maybe then something like this is enough but did not test it:

FROM php:8.2.0RC4-zts-bullseye AS php-base

ENV PHP_URL="https://github.com/dunglas/php-src/archive/refs/heads/frankenphp-8.2.tar.gz"
ENV PHP_ASC_URL=""
ENV PHP_SHA256=""

FROM golang:bullseye AS builder

# ...

FROM php-base AS final

# ...

Update for me it did work: Dockerfile

alexander-schranz avatar Oct 17 '22 21:10 alexander-schranz

I also just made it work on this PR, I built it and ran it successfully on my machine, but with the initial approach 😅

Pierstoval avatar Oct 18 '22 08:10 Pierstoval

you are a boss man ! i test soon

MakFly avatar Oct 18 '22 08:10 MakFly

i test now , its fonctionnal ! thanks !

MakFly avatar Oct 18 '22 09:10 MakFly

Fixed by #33. Thanks for the PR!!

dunglas avatar Oct 19 '22 05:10 dunglas