Skip to content
Advertisement

How to enable php extensions when using the image php:7.2-apache with docker-compose?

I want to run a apache webserver with php extension inside container using docker compose as deployment.

My compose file looks like this:

version: '3.1'

services:
  php:
    image: php:7.2-apache
    ports:
      - 8089:80
    volumes:
      - ./php/www:/var/www/html/

how can I enable the following extensions.

 apache2
 php7.2
 php-xdebug
 php7.2-mcrypt
 php-apcu
 php-apcu-bc
 php7.2-json
 php-imagick
 php-gettext
 php7.2-mbstring

Advertisement

Answer

First of all you can run php -m in php container to see installed and enabled modules.

You can edit your docker-compose.yml like this:

version: '3.1'

services:
  php:
    # image: php:7.2-apache # remember to comment this line
    build: .
    ports:
      - 8089:80
    volumes:
      - ./php/www:/var/www/html/

Create a file called Dockerfile beside docker-compose.yml with the following contents:

FROM php:7.2-apache
# then add the following `RUN ...` lines in each separate line, like this:
RUN pecl install xdebug && docker-php-ext-enable xdebug
...

Finally, let’s go one by one:

apache2

Is installed.

php7.2

Is enabled.

php-xdebug

Add Dockerfile:

RUN pecl install xdebug && docker-php-ext-enable xdebug
php7.2-mcrypt

Add to Dockerfile:

RUN apt-get install libmcrypt-dev
RUN pecl install mcrypt && docker-php-ext-enable mcrypt
php-apcu

Add to Dockerfile:

RUN pecl install apcu && docker-php-ext-enable apcu
php-apcu-bc

Add to Dockerfile:

RUN pecl install apcu_bc
RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini
RUN echo 'extension=apc.so' >> /usr/local/etc/php/php.ini
php7.2-json

Is installed.

php-imagick

Add to Dockerfile:

RUN apt install -y libmagickwand-dev --no-install-recommends && 
    pecl install imagick && docker-php-ext-enable imagick

php-gettext

RUN docker-php-ext-install gettext && 
    docker-php-ext-enable gettext

php7.2-mbstring

Is enabled.
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement