Modifying php.ini in 2.0 builds




I am running PHP builds in CircleCI 2.0 but so far I have been unable to modify the php.ini file in order to, for example, set a default timezone (otherwise the builds fail).

Running this command:

  • run: echo “date.timezone = UTC” >> /opt/circleci/php/$(phpenv global)/etc/php.ini

Fails with the following error:

/bin/bash: phpenv: command not found
/bin/bash: /opt/circleci/php/$(phpenv global)/etc/php.ini: No such file or directory
Exited with code 1

How can this be achieved using the 2.0 builds?

Thank you.


If phpenv is not available, presumably you can just install it prior to that build step. A quick search reveals this resource which says the utility is on GitHub. So, I guess you need to install Git, then clone this utility, then add a symlink to a folder in your PATH?

Failing that, swap to the standard CircleCI Docker build, and install your own version of PHP.


This entire command would be wrong. That command is intended for CircleCI 1.0 where we installed PHP to a custom location.

If you’re using CircleCI 2.0, PHP will be installed wherever the Docker image you’re using decides to install it.

For example, if you are using the official Docker Library PHP image or CircleCI’s PHP images (which is based on the official one), they suggest you to drop in .ini files into /usr/local/etc/php/.


Thank you for your answers.

Indeed, it was an easy solution. I did try to create the file at that same folder using echo, but sudo didn’t work. It turned out I needed to use tee:

echo -e "[Date]\ndate.timezone = UTC" | sudo tee /usr/local/etc/php/php.ini > /dev/null