简体   繁体   中英

What do docker-php-ext-configure, docker-php-ext-install and docker-php-ext-enable do?

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.

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 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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM