Sign inSign up

j33r/php-fpm

By j33r

•Updated over 4 years ago

php-fpm docker image based on alpine

Image
0

3.5K

j33r/php-fpm repository overview

⁠docker-php-fpm

Drone (cloud) Docker Image Size (latest by date) MicroBadger Layers Docker Pulls DockerHub

A docker image for php-fpm⁠ based on Alpine Linux⁠ and without root process⁠

⁠Supported tags

TagsAlpinePhpSizeLayers
latest, stable, master3.127.3MicroBadger Layers (tag)
dev3.127.3MicroBadger Layers (tag)
composer3.127.3MicroBadger Layers (tag)
symfony3.127.3MicroBadger Layers (tag)

⁠What is PHP-FPM?

From php.net⁠:

PHP is a popular general-purpose scripting language that is especially suited to web development. Fast, flexible and pragmatic, PHP powers everything from your blog to the most popular websites in the world.

⁠How to use these images

docker run \
    --detach \
    --interactive \
    --name php-fpm \
    --user $(id -u):$(id -g)
    --env TZ=Europe/Paris
    --volume /etc/localtime:/etc/localtime:ro
    j33r/php-fpm:latest

⁠Volume mounts

  • /app: the directory containing the application
  • /etc/php7/php-fpm.conf: if you want overwrite default the php-fpm.conf⁠
  • /etc/php7/conf.d/00_custom.ini: if you want overwrite default php.ini config⁠
  • /app/phpinfo.php instead of running an application you can mount this file to get php info⁠
  • /php the directory where php store the php-fpm.pid⁠ and php-fpm.socket⁠ files it's virtual volume so you can share it between container.
docker run \
    --detach \
    --interactive \
    --name php-fpm \
    --user $(id -u):$(id -g) \
    --volume /path/to/your/php-fpm.conf:/etc/php7/php-fpm.conf \
    --volume /path/to/your/php.ini:/etc/php7/conf.d/00_custom.ini \
    --volume /path/to/your/app:/app \
    --volume php:/php \
    --volume /etc/localtime:/etc/localtime:ro \
    j33r/php-fpm:latest

You should create directory before run the container otherwise directories are created by the docker deamon and owned by the root user

⁠Environment variables

To change the timezone of the container set the TZ environment variable. The full list of available options can be found on Wikipedia⁠.

You can also set the HOME environment variable this is usefull to get in the right directory when you attach a shell in your docker container.

⁠Php Extension

TagsPhp-ExtensionsPackages ManagersFrameworksAdditional packages
latest, stable, masterfpm, curl, gmp, intl, mbstring, xml, zip, ctype, dom, fileinfo, iconv, gd, json, opcache, phar, session, simplexml, xmlreader, xmlwriter, tokenizer, zlib, mysqli , pdo_sqlit, pdo_mysql, pdo_pgsql
devsame as master
composersame as mastercomposer
symfonysame as mastercomposer, npm, yarnsymfonyNode.js

⁠Socket vs port

By default this image use socket protocol to bind php-fpm to a web-server (apache⁠, nginx⁠...). Socket file path is accessible on /php/php-fpm.socket If you want use tcp protocol instead i need to overwrite listen value in php-fpm.conf⁠ to listen = 0.0.0.0:9000

⁠Logs

If you use this image for developement purpose you will need to see some to debug your stuff. By default php's error and access logs are redirected⁠ to container logs.

docker logs --follow php-fpm
# or with docker-compose
docker-compose log --follow php-fpm
# Ctrl+C to quit

⁠Docker Compose LEMP

docker-compose⁠ can help with defining the docker run config in a repeatable way rather than ensuring you always pass the same CLI arguments.

(Linux + Engine x + Mysql + Php)

Here's an example docker-compose.yml config. Don't forget to modify db passwords specialy if you use this stack in produstion :

version: "3"

services:
  php:
    image: j33r/php-fpm:latest    
    user: "${UID:-1000}:${GID:-1000}"
    restart: unless-stopped
    environment:
      - HOME=/app
      - TZ=Europe/Paris
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./php-fpm.conf:/etc/php7/php-fpm.conf
      - ./php_custom.ini:/etc/php7/conf.d/00_custom.ini
      - ./myapp:/app
      - php:/php

  nginx:
    image: nginxinc/nginx-unprivileged:alpine
    user: "${UID:-1000}:${GID:-1000}"
    restart: unless-stopped
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./nginx_default.conf:/etc/nginx/conf.d/default.conf
      - ./myapp:/app
      - php:/php
    ports:
      - "0.0.0.0:8080:8080"

  db:
    image: mariadb:latest
    container_name: db
    restart: unless-stopped
    volumes:
      - db:/var/lib/mysql/data
    environment:
      - MYSQL_RANDOM_ROOT_PASSWORD=yes
      - MYSQL_DATABASE=database
      - MYSQL_USER=db_user
      - MYSQL_PASSWORD=db_password

  # db:
  #  image: postgres:alpine
  #  container_name: postgres
  #  restart: unless-stopped
  #  networks:
  #    - php-app
  #  volumes:
  #    - db:/var/lib/postgresql/data
  #  environment:
  #    - POSTGRES_USER=db_user
  #    - POSTGRES_PASSWORD=db_password
  #    - POSTGRES_DB=database

volumes:
  php:
  db:

⁠Contributions

⁠Short Story
# fork this repo then :
git clone https://github/<YourName>/docker-php-fpm.git
cd docker-php-fpm
git checkout dev
git pull origin dev
# Do what you need to do, when you'r done then
git add <modified.file> <second.modified.file> <whatever>
git commit -m 'Your message that describe your change'
git push origin dev
# Submit a pull-request
⁠Long Story
  • Fork this repo⁠

  • Clone your fork of this repo
    git clone https://github/<YourName>/docker-php-fpm.git

  • Always work on the dev branch
    cd docker-php-fpm
    git checkout dev

  • be sure your fork's dev branch is up to database
    cd docker-php-fpm
    git pull origin dev

  • Do what you need to do and when you'r done then
    For typo please try to make less commits as possible.

  • Add and commit your modifications
    git add <modified.file> <second.modified.file> <whatever>
    git commit -m 'Your message that describe your change'

  • push on your fork
    git push origin dev \

  • And finaly open a pull request⁠ comparing your dev branch with mine

If you find a vulnerability please contact me by mail

⁠License

This project is under the GNU Generic Public License v3⁠ to allow free use while ensuring it stays open.

Tag summary

Content type

Image

Digest

Size

49.9 MB

Last updated

over 4 years ago

docker pull j33r/php-fpm