Is it possible to install PHP7.4 on stock Alpine 3.12 Docker image?
Asked Answered
I

4

11

Is it possible to install PHP7.4 on stock Alpine 3.12 Docker image?

I have seen this repo and its dockerfile which is using bintray cert and repository path, but I was wondering if there is a more "standard/Alpine" way of doing this natively?

Incorporating answered 10/7, 2020 at 14:48 Comment(0)
C
14

You can use below Docker image.

FROM alpine:3.12
RUN apk add --no-cache  --repository http://dl-cdn.alpinelinux.org/alpine/edge/community php
RUN php -v

output

Step 3/3 : RUN php -v
 ---> Running in 9900e66f4b71
PHP 7.4.7 (cli) (built: Jun 14 2020 23:46:20) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Celebrity answered 10/7, 2020 at 15:56 Comment(3)
Do not mix two distro versions (3.12 and edge), just use FROM alpine:edge, I've written this as an answer instead of a comment to include the details: https://mcmap.net/q/968187/-is-it-possible-to-install-php7-4-on-stock-alpine-3-12-docker-imageLiverpool
@ElanRuusamäe apine:edge is a development branch, it will not only install PHP from development branch but all other packages too. while in the above docker image rest package will be used from alpine:3.12 only the php7.4 will be installed from dev branch.Celebrity
and that's the problem, php on edge is built with libraries from edge, but you have installed libraries from 3.12 and php from edge, that brings linking incompatibilities as described in my linked post, igbinary.so: php_error_docref0: symbol not found in the exampleLiverpool
K
7

If you want to see a full fledged example it's always best to investigate the vendor's Dockerfile.

This is from image php:7.4-fpm-alpine3.12:

https://github.com/docker-library/php/blob/86c8ec4d387132b65dbe6c5ab1747f858e03852e/7.4/alpine3.12/fpm/Dockerfile

As you can see, they add a lot of stuff to ensure PHP runs smooth and startup / context problems are solved.

Kidding answered 13/7, 2020 at 15:35 Comment(0)
L
4

Use alpine edge:

FROM alpine:edge
RUN apk add php
RUN php -v

This is update to Adiii answer suggesting to mix two alpine versions (3.12 and edge), this is terrible outcome, and difficult to understand what went wrong. You may end up with library errors, because it mixed one package from 3.12 and other package from edge:

/ # php -m
PHP Warning:  PHP Startup: Unable to load dynamic library 'igbinary.so' (tried: /usr/lib/php7/modules/igbinary.so (Error relocating /usr/lib/php7/modules/igbinary.so: php_error_docref0: symbol not found), /usr/lib/php7/modules/igbinary.so.so (Error loading shared library /usr/lib/php7/modules/igbinary.so.so: No such file or directory)) in Unknown on line 0 
Liverpool answered 20/8, 2020 at 14:26 Comment(0)
B
0

Use alpine:

FROM alpine:3.14

php 7.4.33

Boccherini answered 17/7 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.