Alpine v3.7 is now deprecated and removed from this documentation. Your scripts will not stop working since the files are still available but they will not be receiving new builds from now on.
PHP 7.1.x is now deprecated and removed from this documentation. Your scripts will not stop working since the files are still available but they will not be receiving new builds from now on.
PHP 7.0.x is now deprecated and removed from this documentation. Your scripts will not stop working since the files are still available but they will not be receiving new builds from now on.

Each version is available on a separate repository, choose the one you want and follow the instructions below:

Repository Conflicts

In some cases, the packages on the repositories may present conflicts with official packages.

To solve that, each page was aliases as php-name, without the 7 indicator.

Considering this, all installs are now encouraged to reference the virtual names when installing.

The examples on this documentation are now updated to reflect this decision.

The original names are kept, and it should not break working scripts.

Base Images

If you want, you can use the base images as your starting point on this repository:

The available images are:

Image Name

Tag

FROM Example

Description

codecasts/alpine-3.9

php-7.3

FROM codecasts/alpine-3.9:php-7.3

PHP 7.3 on Alpine v3.9

codecasts/alpine-3.8

php-7.3

FROM codecasts/alpine-3.8:php-7.3

PHP 7.3 on Alpine v3.8

codecasts/alpine-3.8

php-7.2

FROM codecasts/alpine-3.8:php-7.2

PHP 7.2 on Alpine v3.8

Snippets

The following code snippets are intended for quick usage on either shell scripts or Dockerfile

Notice that main and community official repositories must be enabled.

Dockerfile

You may skip the ca-certificates part if you replace HTTPS by HTTP but you should not. PHP packages will eventually install ca-certificates anyway.

# Versions 3.8 and 3.7 are current stable supported versions.FROM alpine:3.9# trust this project public key to trust the packages.ADD https://dl.bintray.com/php-alpine/key/php-alpine.rsa.pub /etc/apk/keys/php-alpine.rsa.pub## you may join the multiple run lines here to make it a single layer# make sure you can use HTTPSRUN apk --update add ca-certificates
# add the repository, make sure you replace the correct versions if you want.RUN echo"@php https://dl.bintray.com/php-alpine/v3.9/php-7.3">> /etc/apk/repositories
# install php and some extensions# notice the @php is required to avoid getting default php packages from alpine instead.RUN apk add --update php@php
RUN apk add --update php-mbstring@php
RUN apk add --update php-you-extension-name-here@php

Bash / Shell scripting

You may skip the ca-certificates part if you replace HTTPS by HTTP but you should not. PHP packages will eventually install ca-certificates anyway.