Giter Site home page Giter Site logo

huynhpl-1596 / docker-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sun-asterisk-research/docker-php

0.0 0.0 0.0 207 KB

Ready-to-use PHP image for modern web app

License: MIT License

Shell 33.96% Makefile 0.29% HCL 18.57% Dockerfile 47.18%

docker-php's Introduction

PHP Docker Image

PHP images based on the official PHP image, ready to use for modern web app and easily configurable via environment variables.

GitHub CI build status

Image variants

Image tags follow the same pattern as the official image.

There are 3 variants (PHP CLI, PHP-FPM, Nginx) based on Alpine and Debian to fit your specific use cases.

sunasteriskrnd/php:<version>-cli

This variant contains only the PHP CLI tool. Useful when you only need to run PHP code and not serving a web app. Example use cases are running cronjob commands or a background job worker.

sunasteriskrnd/php:<version>-fpm

This variant contains PHP-FPM. You will need a web server that support FastCGI protocol to server the web app. Use this variant if you've already had a web server running and want to scale only the PHP-FPM process.

PHP-FPM Healthcheck

Healthcheck for php-fpm image is included as a script php-fpm-healthcheck.

docker run --rm -d  \
    --health-cmd=php-fpm-healthcheck \
    --health-interval=15s \
    --health-timeout=3s \
    --health-retries=3 \
    sunasteriskrnd/php:fpm

Using docker-compose:

healthcheck:
  test: ["CMD", "php-fpm-healthcheck"]
  interval: 15s
  timeout: 3s
  retries: 3

sunasteriskrnd/php:<version>-nginx

This variant is based on the fpm variant and comes with NGINX webserver to serve your PHP application.

Usage

Assuming you are in the directory containing your index.php file. Run this command to create a container to serve your application on port 80.

docker run -d -p 80:80 -v "$PWD":/var/www/html sunasteriskrnd/php:7.4-nginx

Using a Dockerfile

Assuming src/ is the directory containing your PHP code with an index.php file. You can use the nginx variant as base image for your image as below.

FROM sunasteriskrnd/php:7.4-nginx

COPY src/ /var/www/html/

Changing default nginx root

By default, the nginx image serves from /var/www/html directory. If you wish to change this location, specify the DOCUMENT_ROOT environment variable. For example, to change the root to /srv/application, your Dockerfile may look like this:

FROM sunasteriskrnd/php:7.4-nginx

ENV DOCUMENT_ROOT=/srv/application

COPY src/ /srv/application

sunasteriskrnd/php:<version>-<base>

Images are either based on Alpine or Debian. Supported versions are Alpine 3.14 and 3.15, Debian buster and bullseye.

For example, 8.1-cli-bullseye contains PHP 8.1 CLI based on Debian bullseye.

Tag aliases

All variants have some tag aliases beside the full tag in the format <version>-<variant>-<base>. Any component in the format can be omited and the default value for it will be used. Major, minor or patch version can be used for <version>.

For example, 8.1-cli-bullseye, 8.1-cli, 8.1, 8, cli all refers to the same image. See the docker-bake.hcl file for all tags available.

Currently, the default is PHP 8.1 CLI variant on Debian bullseye.

Configuration

Configuration via environment variables is supported. Environment variables prefixed with PHP. are set as PHP configurations. Environment variables prefixed with PHP_FPM. are set as configuration for the www pool (fpm and nginx variants only). For example:

docker run --rm -it \
    -e PHP.memory_limit=256M \
    -e PHP.post_max_size=64M \
    -e PHP.upload_max_file_size=64M \
    sunasteriskrnd/php
docker run --rm -it \
    -e PHP.memory_limit=256M \
    -e PHP_FPM.pm=ondemand \
    -e PHP_FPM.pm.max_children=40 \
    sunasteriskrnd/php:fpm

Installed extensions

The following extra PHP extensions are installed.

  • bcmath
  • gd (with JPEG support)
  • mysqli
  • opcache
  • pdo_mysql
  • pgsql
  • pdo_pgsql
  • redis
  • zip

You may install more extensions using the same method used with the official PHP image.

docker-php's People

Contributors

daothaison avatar thphuong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.