Both types of installation look the same, but the difference is in the localisation of ini files. The standard path to ini files for local PHP is /usr/local/etc/php. The Docker installation uses the same path, but you can find two files, php.ini-development and php.ini-production, and a folder called conf.d. If you add phpinfo() into both systems, you can see this:
And that is the problem. Unfortunately, PHP is looking for the default php.ini file at the default path. Files named ini-development or ini-production are not accepted. Other ini files can be loaded from a different location: /usr/local/etc/php/conf.d.
1/ If you want to upload files with default values, you can rename one of the files in /usr/local/etc/php/. In Dockerfile like this:
{% c-block language="markdown" %}
FROM PHP:apache
WORKDIR /var/www/html
COPY . . #copy your awesome app to workdir
RUN mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
{% c-block-end %}
2) If you want to upload some files with default values and some with custom values you can use a command echo after renaming the files as in solution no. 1 like this:
{% c-block language="markdown" %}
FROM PHP:apache
WORKDIR /var/www/html
COPY . . #copy your awesome app to workdir
RUN mv /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini \
&& echo “my_values” > /usr/local/etc/php/conf.d/my_php_ini.ini
{% c-block-end %}
3) For using only files with custom values, we can use echo or multiple echo commands, or we can use our own ini file in repo and copy to the correct path. If we are using pipeline from GitLab, we can use the echo environment (GitLab ENV) for an ini file to path /usr/local/etc/php/conf.d/
{% c-block language="markdown" %}
FROM PHP:apache
WORKDIR /var/www/html
COPY . . #copy your awesome app to workdir
COPY “path_to_your_ini_file(s)” /usrlocal/etc/php/conf.d
{% c-block-end %}
or:
{% c-block language="markdown" %}
RUN echo “my_values” > /usr/local/etc/php/conf.d/my_php_ini.ini (creating file)
RUN echo “my_other_values” >> /usr/local/etc/php/conf.d/my_php_ini.ini (add_lastline_into_file)
{% c-block-end %}
See you soon for the next episode of our DevOps series.