Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store the docker-php-ext files?

I have set up a Symfony4 project with in a Docker container.

I followed the Jobeet-Tutorial where they use the phpdocker.io - generator.

All works perfect but very slow. So I want to speed up and enable the opcache and configure it.

I found helpful links in the net. So I added to my Dockerfile this:

RUN docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install opcache
# Copy configuration
COPY config/opcache.ini $PHP_INI_DIR/conf.d/

The problem is that I don't have this helperscripts:

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

So I decided to search it in the internet and copy it into my project.

Now I have it in the php-fpm folder of my docker directory.

My directory looks like this now - the scripts are in the beneath the Dockerfile:

enter image description here

Is there any other step I forgot to do, like registering these scripts somewhere?

like image 553
Slowwie Avatar asked Oct 24 '25 02:10

Slowwie


1 Answers

The most immediate answer to your question is that you need to copy those scripts into the Docker image you are building. To do that, you should create a subdirectory within the php-fpm directory named bin and put all of those scripts in that directory. Then, in your Dockerfile:

COPY bin /usr/local/bin

Now when you try to use that image, the scripts will be within your executable PATH.

However

Those docker-php-ext-* scripts you found are from the PHP project's official Docker images and are intended to be used with those images.

You are using the phpdockerio/php73-fpm:latest image, which seems to use ubuntu:bionic as a base image. These scripts depend heavily on the PHP Dockerfiles, which do a bunch of preparatory steps, such as downloading the source code for the PHP interpreter itself to /usr/src. Making these scripts run directly in a phpdockerio container would be a very involved process.

That leaves you with 2 options:

  1. Forgo the scripts and install Ubuntu's prebuilt packages. You seem to already have the apcu, apcu-bc, cli, curl, json, mbstring, opcache, readline, xml, and zip PHP extensions installed. You can see the full list of packages that are available from the default repos this way by running

    docker run --rm -it phpdockerio/php73-fpm:latest bash -c 'apt-get update && apt search ^php7.3-';
    

    When you know which packages you want, you can add them to your Dockerfile.

 
  1. Switch to using an official PHP image instead so you can use the docker-php-ext-* scripts. The phpdocker-io image you are using is essentially PHP7.3-FPM on Ubuntu, and the closest official PHP image to that is php:7.3-fpm-stretch (Debian 9). You can build and install the extensions listed in Option 1 by changing your PHP-FPM Dockerfile to:

    FROM php:7.3-fpm-stretch
    
    # Run in Bash instead of Bourne shell to get lists
    RUN ["bash", "-c", " \
        #Exits on error or unbound variable. Now we can use semicolons instead of
        #ampersands
        set -eu; \
    \
        ext_build_dependencies=( \
            #Needed to build php-curl
            libcurl4-gnutls-dev \
            \
            #Needed to build php-mbstring
            libedit-dev \
            \
            #Needed to build php-xml \
            libxml2-dev \
            \
            #Needed to build php-zip
            zlib1g-dev libzip-dev \
        ); \
    \
        apt-get update; \
        apt-get install -y ${ext_build_dependencies[@]}; \
    \
        #Build the extensions
        docker-php-ext-install curl json mbstring readline xml zip ; \
        pecl install apcu apcu_bc; \
    \
        apt-get purge -y ${ext_build_dependencies[@]}; \
        apt-get autoremove -y; \
        apt-get clean -y; \
    "]
    
 

If Ubuntu 18 and Debian were binary-compatible (they're not), you could try a third option, which would be building the extensions using a PHP image, then copying over the built extensions as the second stage of a multi-stage build. This would be possible if your image uses the same Linux flavor as as the PHP image does. For example, if your image were based on alpine:3.8, you could use php:7.3-fpm-alpine3.8 to build your extensions and copy them over.

like image 60
zrhoffman Avatar answered Oct 26 '25 17:10

zrhoffman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!