Skip to content

🐳 Alpine based docker image with Apache (prefork) & PHP module.

Notifications You must be signed in to change notification settings

prog/docker-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

Base docker image for PHP applications

release docker build status docker pulls dockerhub stars

Alpine based docker image with Apache (prefork) & PHP module.

Supported tags / versions

Image tag starts with image version number followed by the versions of php, apache and alpine. Some parts of version numbers can be omitted to emulate semantic versioning.

Latest release

  • prog/php:0.1[.2]--php7[.1]-apache[2[.4]]-alpine[3[.6]]

  • prog/php:0.1[.2]--php5[.6]-apache[2[.4]]-alpine[3[.6]]

  • All Releases

Customization

Some helper scripts are bundled with the image to make it easier to setup and customize.

Install PHP modules

This image comes with no extra php modules. You need to add all modules required by your application yourself. A helper script is provided for this purpose:

image--php-add-mod [list of php modules]
RUN image--php-add-mod \
    cli gd mbstring pdo session ...  

Edit PHP config

Add configuration directives to the end of the php.ini file:

image--php-config [directives]
RUN image--php-config \
    expose_php=Off \
    max_execution_time=10 \
    memory_limit=32M \
    post_max_size=20M \
    upload_max_filesize=20M \
    date.timezone="Europe/Bratislava"

Enable Apache modules

Only minimal set of apache modules are enabled by default. Use the helper script to enable required modules in apache config file:

image--apache-enable-mod [list of apache modules]
RUN image--apache-enable-mod \
    deflate filter rewrite ...

Change document root

Apache is set to serve /app directory by default. You can change it by running:

image--apache-set-docroot [path]
image--set-docroot [path]
RUN image--set-docroot /app/docroot

Initialization script

The entrypoint is set to run an initialization script (/usr/bin/image--init) before executing Apache when container is started. Initialization script is empty by default. You can add your own instructions there or replace the whole file.

The helper script can be used to add instructions into the initialization script:

image--on-init [script lines]
RUN image--on-init \
   '# My application initialization' \
   'echo "Starting my awesome application!"' \
   'chmod 777 /app/temp'

Full usage example

Add the Dockerfile to your project and edit it to your needs:

FROM prog/php:0.1--php7-apache-alpine

## install required php modules
RUN image--php-add-mod cli iconv json mbstring pdo_mysql session sqlite3 tokenizer

## edit php config
RUN image--php-config \
   'expose_php=Off' \
   'max_execution_time=10' \
   'memory_limit=32M' \
   'post_max_size=20M' \
   'upload_max_filesize=20M' \
   'date.timezone="Europe/Bratislava"'

## enable required apache modules
RUN image--apache-enable-mod deflate filter rewrite

## set document root
RUN image--set-docroot /app/public

## set container's initialization script
RUN image--on-init \
   'chmod 777 /app/temp /app/log /app/sessions' \
   'if [ "$''{APP__DB_MIGRATIONS}" ]; then' \
   '	/app/bin/db-migrations $''{APP__DB_MIGRATIONS}' \
   'fi'

## copy application into image, create necessary directories
WORKDIR /app
COPY vendor vendor
COPY bin bin
COPY src src
COPY public public
RUN mkdir log temp sessions

## declare volumes, expose ports
VOLUME /app/log
VOLUME /app/sessions
EXPOSE 80

Build your image:

docker build . -t my-awesome-app

Run it:

docker run \
  -e 'APP__DB_DSN=mysql:host=localhost;dbname=database' \
  -e 'APP__DB_USER=user' \
  -e 'APP__DB_PASSWORD=password' \
  -e 'APP__DB_MIGRATIONS=main' \
  -e 'APP__DEBUG_MODE=off' \
  -v 'my-awesome-app__log:/app/log' \
  -v 'my_awesome-app__sessions:/app/sessions' \
  -p '80:80' \
  my-awesome-app

About

🐳 Alpine based docker image with Apache (prefork) & PHP module.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages