Skip to content

Discussion: how to best use php.ini-production and php.ini-development  #873

@claycogg

Description

@claycogg

Hello,

I am using the php7.3 image to serve a php website (as most do). We need to swap between the 2 .inis depending on if we are running in a development environment or production environment.

How is this typically handled? Both files are in the container so is there some strategy for changing which is used at run-time? The README has limited input on the subject and understanding the best way to use both seems to require more knowledge than is in the README.

It is strongly recommended to use the production config for images used in production environments!

The default config can be customized by copying configuration files into the $PHP_INI_DIR/conf.d/ directory.

I have a few ideas, but could use some help.

Proposal #1

The first idea is to make 2 containers and run the following with ENVIRONMENT set differently. This lets us continue to manage a single Dockerfile, but now we have 2 images.

RUN mv "$PHP_INI_DIR/php.ini-${ENVIRONMENT}" "$PHP_INI_DIR/php.ini"

This isn't the best solution in my eyes as it means managing 2 different containers that differ by a single file. So we thought...

Proposal #2

What if we extend the entry point? Instead of just starting apache we would also run the move command, and provide ENVIRONMENT at runtime. The downside of this is complicating the entrypoint by increasing the complexity of the command it runs, which is not typically how entrypoint is used.

Proposal #3

Create 2 different directories, one for production and development and use apache's PHPhIniDir to set where apache looks for php.ini. Then we can provide an environment variable at runtime to change where Apache looks, allowing us to have a single container with both configurations. I think this is the best option.

Thank you for any input you have on this problem!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUsability question, not directly related to an error with the image

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions