Sign inSign up

phpearth/php

By phpearth

•Updated over 7 years ago

Docker For PHP Developers - Customized Docker images with PHP, Nginx and OpenLiteSpeed.

Image
25

100K+

phpearth/php repository overview

⁠Docker for PHP developers

Build Status Docker Automated build MIT License

Carefully crafted Docker images for PHP developers with PHP 7.3, PHP 7.2, PHP 7.1, PHP 7.0, Nginx, OpenLiteSpeed, Apache HTTP Server, and Lighttpd.

PHP.earth

  • Fast and simple PHP extensions installation
  • Optional Composer installation
  • Optional PHPUnit installation
  • runit⁠ for running multiple services without overhead
  • Alpine base image with PHP.earth PHP repositories⁠
  • Optimized Docker image sizes
  • Multiple PHP versions

⁠Documentation

Documentation with Docker and PHP recipes is available on PHP.earth⁠.

⁠Docker tags

The following list contains all current Docker tags and what is included in each.

SystemDocker TagFeaturesSize
PHP 7.3.0@Alpine 3.8.1latest, 7.3⁠Small PHP CLI
7.3-cli⁠PHP CLI
7.3-lighttpd⁠Lighttpd 1.4.49
7.3-litespeed⁠OpenLiteSpeed 1.5.0 RC3
7.3-nginx⁠Nginx 1.14.1, FPM
7.3-apache⁠Apache 2.4.35
7.3-cgi⁠PHP CGI
PHP 7.2.12@Alpine 3.8.17.2⁠Small PHP CLI
7.2-cli⁠PHP CLI
7.2-lighttpd⁠Lighttpd 1.4.49
7.2-litespeed⁠OpenLiteSpeed 1.5.0 RC3
7.2-nginx⁠Nginx 1.14.1, FPM
7.2-apache⁠Apache 2.4.35
7.2-cgi⁠PHP CGI
PHP 7.1.24@Alpine 3.8.17.1⁠Small PHP CLI
7.1-cli⁠PHP CLI
7.1-lighttpd⁠Lighttpd 1.4.49
7.1-litespeed⁠OpenLiteSpeed 1.5.0 RC3
7.1-nginx⁠Nginx 1.14.1, FPM
7.1-apache⁠Apache 2.4.35
7.1-cgi⁠PHP CGI
PHP 7.0.32@Alpine 3.7.07.0⁠Small PHP CLI
7.0-cli⁠PHP CLI
7.0-lighttpd⁠Lighttpd 1.4.48
7.0-litespeed⁠OpenLiteSpeed 1.5.0 RC3
7.0-nginx⁠Nginx 1.12.2, FPM
7.0-apache⁠Apache 2.4.35
7.0-cgi⁠PHP CGI

Tags follow PHP release cycle and PHP supported versions timeline⁠.

PHPActive Support UntilSecurity Support UntilInfo
7.3TBDTBDCurrent recommended branch for production
7.22019-11-302020-11-20Previous stable branch
7.12018-12-012019-12-01Previous branch for legacy projects
7.02017-12-032018-12-03Previous branch for legacy projects, not supported anymore

⁠Quick usage

⁠Nginx

Dockerfile for running Nginx HTTP server with PHP FPM:

FROM phpearth/php:7.3-nginx

Build Docker image and run Docker container:

docker build -t custom-php .
docker run --name custom-php-container -p 80:80 -d custom-php
⁠PHP CLI

To run a CLI PHP script:

docker run -it --rm -v `pwd`:/usr/src/myapp -w /usr/src/myapp phpearth/php php script.php
⁠Composer

To install Composer:

FROM phpearth/php:7.3-nginx

RUN apk add --no-cache composer
⁠PHPUnit

To install PHPUnit:

FROM phpearth/php:7.3-nginx

RUN apk add --no-cache phpunit
⁠OpenLiteSpeed

To run OpenLiteSpeed web server:

FROM phpearth/php:7.3-litespeed
⁠Lighttpd

To run Lighttpd web server:

FROM phpearth/php:7.3-lighttpd
⁠PHP extensions

To install additional PHP extensions, you can use packages from the PHP.earth Alpine repository⁠:

FROM phpearth/php:7.3-nginx

RUN apk add --no-cache php7.3-sodium php7.3-intl php7.3-pdo_mysql

or install them with pecl:

apk add --no-cache php7.3-dev gcc g++
pecl install {extension-name}
⁠Missing extension?

In case you'd need an additional extension in the PHP.earth repository, open an issue⁠.

⁠Docker Stack

Docker Stack is way of orchestration of Docker services and simplifies running multiple services of your application. In this example we'll run an Nginx web server with PHP 7.3 FPM with docker-compose.yml file. In a new project directory create a Dockerfile:

FROM phpearth/php:7.3-nginx

The docker-compose.yml file:

version: '3.3'

services:
  app:
    image: my-dev-image
    volumes:
      - .:/var/www/html
    ports:
      - mode: host
        target: 80
        published: 80

The index.php file:

<?php

phpinfo();

Finally we run:

# Initialize a new Swarm for development
docker swarm init
# Build above image
docker build -t my-dev-image -f Dockerfile .
# Deploy the above stack up and running
docker stack deploy -c docker-compose.yaml mystack

And there should be phpinfo() output visible on http://localhost. Make sure there isn't any other service listening on port 80 before running above command.

⁠PHP 7.0, 7.1, PHP 7.2

To use older versions PHP 7.0, 7.1, or 7.2 use Docker images with 7.0, 7.1, or 7.2:

FROM phpearth/php:7.2-nginx

RUN apk add --no-cache composer

⁠PHP.earth Alpine repository

These Docker images include the latest PHP versions and packages for Alpine Linux via the 3rd party PHP.earth Alpine repository⁠.

FROM alpine:3.8

ADD https://repos.php.earth/alpine/phpearth.rsa.pub /etc/apk/keys/phpearth.rsa.pub
RUN echo "https://repos.php.earth/alpine" >> /etc/apk/repositories \
    && apk add --no-cache php7.3

PHP.earth Alpine packages are prefixed with php7.3, php7.2, php7.1, and php7.0.

⁠Building Images

Images are automatically build on Docker Hub⁠.

Docker Cloud and therefore Docker Hub also provides overriding and customization⁠ of various commands when building images automatically.

There are some hooks defined in the docker/hooks folder:

  • hooks/build - executed when building image
  • hooks/post_push - executed after building image, used to push additional tags to Docker Hub.
⁠Labels

Labels⁠ are neat way to expose additional metadata about particular Docker object. We use Label Schema⁠ when defining image labels:

  • build-date - Date and time of the build. Defined as org.label-schema.build-date=$BUILD_DATE, where $BUILD_DATE is set dynamically via above hooks/build script
  • vcs-url - Repository location on GitHub. Defined as org.label-schema.vcs-url="https://github.com/phpearth/docker-php.git"
  • vcs-ref - Reference to commit in Git repository
  • schema-version - Version of the Label Schema in use.
  • vendor - Vendor name of the image creators.
  • name
  • description
  • url

⁠License and contributing

Contributions⁠ are most welcome. This repository is released under the MIT license⁠.

Tag summary

Content type

Image

Digest

Size

6.8 MB

Last updated

over 7 years ago

docker pull phpearth/php