Skip to content

Latest commit

 

History

History
99 lines (63 loc) · 3.7 KB

README.md

File metadata and controls

99 lines (63 loc) · 3.7 KB

Alpine PHP

Build Status

This PHP FPM and PHP CLI docker image based on Alpine. Alpine is based on Alpine Linux, lightweight Linux distribution based on BusyBox. The size of the image is very small, less than 50 MB!

Tags

Versions and tags are based on PHP versions.

Here are the supported tags and respective Dockerfile links.

The cli tag show that the PHP is used for command line and the fpm is designed to be used with PHP-FPM. It is fit with Alpine-Nginx docker image.

PHP 7.0

PHP 7.0 is still using edge/testing repository for PHP7 packages. PHP 7.0 CLI is not available yet, since there's no php7-cli package in the repository.

Getting The Image

This image is published in the Docker Hub. Simply run this command below to get it to your machine.

docker pull matriphe/alpine-php:fpm

Or if you want to use cli image.

docker pull matriphe/alpine-php:cli

Alternatively you can clone this repository and build the image using the docker build command.

Build

This image use Asia/Jakarta timezone by default. You can change the timezone by change the TIMEZONE environment on Dockerfile and then build.

docker build -t repository/imagename:tag .

Configuration

The site data, config, and log data is configured to be located in a Docker volume so that it is persistent and can be shared by other containers or a backup container).

There is volume defined in this image /www that is shared with Nginx container. Please make sure both containers can access the directory. You can store the sites data to this directory.

PHP Configuration

The config is set using environments listed below on build.

ENV TIMEZONE Asia/Jakarta
ENV PHP_MEMORY_LIMIT 512M
ENV MAX_UPLOAD 50M
ENV PHP_MAX_FILE_UPLOAD 200
ENV PHP_MAX_POST 100M

Change it in Dockerfile and you can rebuild your image.

Run The Container

Create and Run The Container

docker run -p 9000:9000 --name phpfpm -v /home/user/public_html:/www:rw -d matriphe/alpine-php:fpm

If you run and want to link Nginx container, make sure you created and run this PHP-FPM the container before running this Nginx container. Make sure the /www volume in PHP-FPM container is mapped.

  • The first -p argument maps the container's port 9000 to port 9000 on the host and used for communication between Nginx and PHP-FPM.
  • --name argument sets the name of the container, useful when starting and stopping the container.
  • The -v argument maps the /home/user/public_html directory in the host to /www in the container with read/write access (rw).
  • -d argument runs the container as a daemon.

Stopping The Container

docker stop phpfpm

Start The Container Again

docker start phpfpm

PHP CLI

To ease the job, make alias for PHP-CLI. Add this line to ~/.bashrc so we can call it as regular php command.

alias php='docker run --rm --name=php-cli -v $(pwd):/www matriphe/alpine-php:cli php'