<commit_before># Docker PHP FPM

Highy configurable PHP FPM container.

PHP app/pool name, username and group (along with uid and gid), app source directory, interface/port/socket PHP listens on are configurable via environment variables; as are any additional packages to be installed upon container startup.

The startup script makes sure to signal `php-fpm` when logfiles are deleted or moved. This can be used in conjunction with `logrotate`, with the caveat that the logrotated logfiles have to be physically *moved or deleted* for the startup script to notice. Hence, it is adviseable to *not* use `copy` or `copytruncate` [logrotate options](http://linux.die.net/man/8/logrotate)

There is also no need to use the `create` option for the error log file (configured via `PHP_ERROR_LOG`), as `php-fpm` will re-create that file automagically.

Licensed under [GNU Affero GPL](https://gnu.org/licenses/agpl.html).

## Usage

This image is meant to be used with `nginx` or any other webserver that supports FastCGI

Usage example with pure `docker`:

```
docker build --tag docker-php-fpm docker-php-fpm/

docker run \
    -e PHP_APP_NAME=myapp \
    -e PHP_APP_USER=myapp_user \
    -e PHP_APP_GROUP=myapp_group \
    -e PHP_APP_LISTEN=/var/run/php/myapp.socket \
    -e PHP_APP_DIR=/opt/myapp/
    -e PHP_ERROR_LOG="/var/log/myapp/error.log" \
    --build-arg INSTALL_PACKAGES="php5-intl php5-ming" \
    -v "/path/to/code/:/opt/myapp/:ro" \
    docker-php-rpm
```

And with `docker-compose` ([v.2](https://docs.docker.com/compose/compose-file/#version-2)):

```
php.myapp:
    build: 
        context: docker-php-fpm/
        args:
            INSTALL_PACKAGES: "php5-intl php5-ming"
    environment:
        PHP_APP_NAME:     "myapp"
        PHP_APP_USER:     "myapp_user"
        PHP_APP_GROUP:    "myapp_group"
        PHP_APP_LISTEN:   "/var/run/php/myapp.socket"
        PGP_APP_DIR:      "/opt/myapp/"
        PHP_ERROR_LOG:    "/var/log/myapp/error.log"
    volumes:
        - ""/path/to/code/:/opt/myapp/:ro""
```

## [Build-time variables](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg)

 - `INSTALL_PACKAGES`

List of packages to `apt-get install` during build, to be used as an alternative to forking this image or using it in the Dockerfile `FROM` clause.

This is the preferred way of installing additional packages (compare: `INSTALL_PACKAGES` environment variable).

## Environment variables

This container is configurable with the following environment variables. However, if a config file is explicitly volume-mounted, it is up to the user to make sure that the user and group combination used in that config file is compatible with `PHP_*` envvars!

 - `PHP_APP_NAME` (default: `"www"`)

Name of the application, used in pool config file name, PHP pool name, etc.

 - `PHP_APP_USER` (default: `"www-data"`)
 - `PHP_APP_UID`

The username to run the `php5-fpm` process as. If the user does not exist, it will be created (with `PHP_APP_UID` as uid, if provided), and will be put in `PHP_APP_GROUP` group.

If both `PHP_APP_USER` and `PHP_APP_UID` are provided, and there is an existing user with `PHP_APP_USER`, but with a different uid, the startup script will fail with an error.

 - `PHP_APP_GROUP` (default: `"www-data"`)
 - `PHP_APP_GID`
 
The group to run the `php5-fpm` process as. If the group does not exist, it will be created (with `PHP_APP_GID` as uid, if provided).

If both `PHP_APP_GROUP` and `PHP_APP_GID` are provided, and there is an existing user with `PHP_APP_GROUP`, but with a different uid, the startup script will fail with an error.

 - `PHP_APP_DIR` (default: `"/opt/php/"`)

Directory with code to run.

 - `PHP_APP_LISTEN` (default: `"[::]:9000"`)

What interface to listen on -- compatible with the `listen` directive of the `php.ini` config file: can be either an `IP:PORT` combination, only a `PORT`, or a `/path/to/unix/socket`.

 - `INSTALL_PACKAGES` (**deprecated** -- use `INSTALL_PACKAGES` build arg instead)
<commit_msg>Update README.md: bugfix, it's `PHP_LISTEN`, not `PHP_APP_LISTEN`<commit_after># Docker PHP FPM

Highy configurable PHP FPM container.

PHP app/pool name, username and group (along with uid and gid), app source directory, interface/port/socket PHP listens on are configurable via environment variables; as are any additional packages to be installed upon container startup.

The startup script makes sure to signal `php-fpm` when logfiles are deleted or moved. This can be used in conjunction with `logrotate`, with the caveat that the logrotated logfiles have to be physically *moved or deleted* for the startup script to notice. Hence, it is adviseable to *not* use `copy` or `copytruncate` [logrotate options](http://linux.die.net/man/8/logrotate)

There is also no need to use the `create` option for the error log file (configured via `PHP_ERROR_LOG`), as `php-fpm` will re-create that file automagically.

Licensed under [GNU Affero GPL](https://gnu.org/licenses/agpl.html).

## Usage

This image is meant to be used with `nginx` or any other webserver that supports FastCGI

Usage example with pure `docker`:

```
docker build --tag docker-php-fpm docker-php-fpm/

docker run \
    -e PHP_APP_NAME=myapp \
    -e PHP_APP_USER=myapp_user \
    -e PHP_APP_GROUP=myapp_group \
    -e PHP_APP_LISTEN=/var/run/php/myapp.socket \
    -e PHP_APP_DIR=/opt/myapp/
    -e PHP_ERROR_LOG="/var/log/myapp/error.log" \
    --build-arg INSTALL_PACKAGES="php5-intl php5-ming" \
    -v "/path/to/code/:/opt/myapp/:ro" \
    docker-php-rpm
```

And with `docker-compose` ([v.2](https://docs.docker.com/compose/compose-file/#version-2)):

```
php.myapp:
    build: 
        context: docker-php-fpm/
        args:
            INSTALL_PACKAGES: "php5-intl php5-ming"
    environment:
        PHP_APP_NAME:     "myapp"
        PHP_APP_USER:     "myapp_user"
        PHP_APP_GROUP:    "myapp_group"
        PHP_APP_LISTEN:   "/var/run/php/myapp.socket"
        PGP_APP_DIR:      "/opt/myapp/"
        PHP_ERROR_LOG:    "/var/log/myapp/error.log"
    volumes:
        - ""/path/to/code/:/opt/myapp/:ro""
```

## [Build-time variables](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables-build-arg)

 - `INSTALL_PACKAGES`

List of packages to `apt-get install` during build, to be used as an alternative to forking this image or using it in the Dockerfile `FROM` clause.

This is the preferred way of installing additional packages (compare: `INSTALL_PACKAGES` environment variable).

## Environment variables

This container is configurable with the following environment variables. However, if a config file is explicitly volume-mounted, it is up to the user to make sure that the user and group combination used in that config file is compatible with `PHP_*` envvars!

 - `PHP_APP_NAME` (default: `"www"`)

Name of the application, used in pool config file name, PHP pool name, etc.

 - `PHP_APP_USER` (default: `"www-data"`)
 - `PHP_APP_UID`

The username to run the `php5-fpm` process as. If the user does not exist, it will be created (with `PHP_APP_UID` as uid, if provided), and will be put in `PHP_APP_GROUP` group.

If both `PHP_APP_USER` and `PHP_APP_UID` are provided, and there is an existing user with `PHP_APP_USER`, but with a different uid, the startup script will fail with an error.

 - `PHP_APP_GROUP` (default: `"www-data"`)
 - `PHP_APP_GID`
 
The group to run the `php5-fpm` process as. If the group does not exist, it will be created (with `PHP_APP_GID` as uid, if provided).

If both `PHP_APP_GROUP` and `PHP_APP_GID` are provided, and there is an existing user with `PHP_APP_GROUP`, but with a different uid, the startup script will fail with an error.

 - `PHP_APP_DIR` (default: `"/opt/php/"`)

Directory with code to run.

 - `PHP_LISTEN` (default: `"[::]:9000"`)

What interface to listen on -- compatible with the `listen` directive of the `php.ini` config file: can be either an `IP:PORT` combination, only a `PORT`, or a `/path/to/unix/socket`.

 - `INSTALL_PACKAGES` (**deprecated** -- use `INSTALL_PACKAGES` build arg instead)

{'fraction_non_alphanumeric': 0.10797137216189535, 'fraction_numerical': 0.0032082922013820336, 'mean_word_length': 3.7122093023255816, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1933358', 'n_tokens_mistral': 2683, 'n_tokens_neox': 2573, 'n_words': 942}