I want to run a apache webserver with php extension inside container using docker compose as deployment.
My compose file looks like this:
JavaScript
x
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.
JavaScript
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:
JavaScript
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:
JavaScript
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:
JavaScript
apache2
Is installed.
JavaScript
php7.2
Is enabled.
JavaScript
php-xdebug
Add Dockerfile
:
JavaScript
RUN pecl install xdebug && docker-php-ext-enable xdebug
JavaScript
php7.2-mcrypt
Add to Dockerfile
:
JavaScript
RUN apt-get install libmcrypt-dev
RUN pecl install mcrypt && docker-php-ext-enable mcrypt
JavaScript
php-apcu
Add to Dockerfile
:
JavaScript
RUN pecl install apcu && docker-php-ext-enable apcu
JavaScript
php-apcu-bc
Add to Dockerfile
:
JavaScript
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
JavaScript
php7.2-json
Is installed.
JavaScript
php-imagick
Add to Dockerfile
:
JavaScript
RUN apt install -y libmagickwand-dev --no-install-recommends &&
pecl install imagick && docker-php-ext-enable imagick
php-gettext
JavaScript
RUN docker-php-ext-install gettext &&
docker-php-ext-enable gettext
php7.2-mbstring
JavaScript
Is enabled.