Back

Local installation of PHP vs. PHP in Docker

30/10/2020
Pavel Trzaskalik

PHP is a server-side scripting language designed for web development, but which can also be used as a general-purpose programming language. PHP can be added to straight HTML or it can be used with a variety of templating engines and web frameworks. PHP code is usually processed by an interpreter, which is either implemented as a native module on the webserver or as a common gateway interface (CGI).

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.

How to solve it

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.

‍

Pavel is a trained DevOps guru and keen SysAdmin in charge of the application lifecycle, continuous integration, continuous deployment, and continuous delivery for both customer and internal SABO projects. He trains software developers in our team and coordinates all DevOps activities. He always has some puns up his sleeve, unpredictably switches to Polish, and likes to cook and bake.

Show profile
SABO Mobile IT logo
SABO Mobile IT – Experience
SABO Mobile IT – Experience
SABO Mobile IT – Experience
SABO Mobile IT – Experience
SABO Mobile IT – Experience

SABO IT

SABO IT develops custom software for companies with complex technical processes, from the control unit through the cloud to enterprise systems, including in regulated environments. It also has its own platforms: SenseDrive for source-verified answers from your own knowledge base, and SABOT for voice control of machines. Software development since 1983, as SABO IT since 2012; the average customer relationship lasts 6.5 years.
ABOUT US

More articles

Artikelbild (Platzhalter)
Recommended for you

What does AI in the enterprise really cost? Why the price per user is the wrong number

Three reports from this year show why compute power is becoming a strategic question for European companies. According to Siemens board member Cedrik Neike, European data centers run 20 to 30 percent above US levels in operating costs, while companies, in his estimate, would pay only 5 to 10 percent more for it.
Guido Stanovski,  October 29, 2026
Read article

Book a meeting

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.