27

I'm trying to set up a LAMP web server using docker and was delighted to discover that the good folks over at php have put together a docker container for php.

Reading through the documentation I found three functions that will ostensibly assist me with the installation of php extensions;

  • docker-php-ext-configure
  • docker-php-ext-install
  • docker-php-ext-enable

Being a complete newcomer to php and having tried and failed to enable php modules using a combination of apk add and php.ini hackery (resulting in .so not found errors), I'm ready to admit defeat and do it the proper way.

Unfortunately, the documentation is remarkable vague about what these commands do and how to use them:

We provide the helper scripts docker-php-ext-configure, docker-php-ext-install, and docker-php-ext-enable to more easily install PHP extensions.

I tried to google it as well, but couldn't find any useful resources online either.

I'm now completely confused between what it means to install, configure and install a php extension, and how commands like apk add php7-* relate to all of this.

Please explain what these functions do, and how you would use them to enable php extensions.

1
  • "a docker container for php" link is giving 404 error Commented Feb 1 at 13:34

3 Answers 3

28

These are helper scripts that helps one install php extensions from source

  • not all extensions are available in a distribution native package manager or pecl
  • even if these exist one may want to configure these differently or optimize

Talking about the scripts

  • docker-php-ext-configure - configure an extension before you build it with docker-php-ext-install. It's executed by docker-php-ext-install, so one should use it if wants to override the defaults
  • docker-php-ext-install - build extension from source, usually executes docker-php-ext-configure for build configuration, enables the extension (php.ini entry) by executing docker-php-ext-enable after all
  • docker-php-ext-enable - enables an already installed extension by adding a specific entry to php.ini. Extensions installed with pecl or native package managers may not be enabled by default thus require this additional step. As mentioned above, extensions installed with docker-php-ext-install are being enabled automatically.
Sign up to request clarification or add additional context in comments.

Comments

2

these functions can help to set-up your PHP configuration, if per example you want to add opcache to your PHP configuation:

firstly you configure as below :

docker-php-ext-configure gd \ --enable-gd-native-ttf \ --with-jpeg-dir=/usr/lib \ --with-freetype-dir=/usr/include/freetype2 && \ docker-php-ext-install gd \ 

and you install your configuration

 && docker-php-ext-install opcache 

and then you can enable it

 && docker-php-ext-enable opcache 

7 Comments

Thanks for this. Could you explain why you would configure before installing, and also, does this mean we don't need to do apt install php-ocache as well?
in PHP if you would Enable GD Library in PHP with LibJPEG, you need to configure this for enabling the gd library, for the second if you need to implement the opcache it depends on which operating system on your docker container you use .
But absolutely you need to do apt install php-ocache for instaling this to your container.
So in order to use the opcache php extension, I would need to apt-get install php-opcache, then docker-php-ext-configure, then docker-php-ext-install and then docker-php-ext-enable?
Also, why would I do apt-get install when I have docker-php-ext-install? What's the difference?
|
2

I had the same question and wasn't satisfied with the level of details of other answers.

The code of the docker-php-ext-install and other utilities is in the PHP docker images. Some examples:

docker-php-ext-install in php7.3-fpm has these interesting parts (omitting option parsing, etc.):

docker-php-source extract cd /usr/src/php/ext # skip usage, option parsing and checking the extension list for ext in $exts; do cd "$ext" [ -e Makefile ] || docker-php-ext-configure "$ext" make -j"$j" make -j"$j" install find modules \ -maxdepth 1 \ -name '*.so' \ -exec basename '{}' ';' \ | xargs -r docker-php-ext-enable ${iniName:+--ini-name "$iniName"} make -j"$j" clean cd "$popDir" done 

So this means the -j$(nproc) I see everywhere specifies that the number of make jobs (commands) to run simultaneously is the same as the number of processors.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.