Last active
September 16, 2024 07:08
-
-
Save evansims/280d63378c9f422f7b5d72e6d16f3806 to your computer and use it in GitHub Desktop.
Dockerfile: php-fpm 7.4-fpm alpine w/ gd bz2 intl mbstring redis mongodb xdebug opcache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM php:7.4-fpm-alpine | |
WORKDIR "/application" | |
# Install essential build tools | |
RUN apk add --no-cache \ | |
git \ | |
yarn \ | |
autoconf \ | |
g++ \ | |
make \ | |
openssl-dev | |
# Optional, force UTC as server time | |
RUN echo "UTC" > /etc/timezone | |
# Install composer | |
ENV COMPOSER_HOME /composer | |
ENV PATH ./vendor/bin:/composer/vendor/bin:$PATH | |
ENV COMPOSER_ALLOW_SUPERUSER 1 | |
RUN curl -s https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer | |
# Setup bzip2 extension | |
RUN apk add --no-cache \ | |
bzip2-dev \ | |
&& docker-php-ext-install -j$(nproc) bz2 \ | |
&& docker-php-ext-enable bz2 \ | |
&& rm -rf /tmp/* | |
# Setup GD extension | |
RUN apk add --no-cache \ | |
freetype \ | |
libjpeg-turbo \ | |
libpng \ | |
freetype-dev \ | |
libjpeg-turbo-dev \ | |
libpng-dev \ | |
&& docker-php-ext-configure gd \ | |
--with-freetype=/usr/include/ \ | |
# --with-png=/usr/include/ \ # No longer necessary as of 7.4; https://github.com/docker-library/php/pull/910#issuecomment-559383597 | |
--with-jpeg=/usr/include/ \ | |
&& docker-php-ext-install -j$(nproc) gd \ | |
&& docker-php-ext-enable gd \ | |
&& apk del --no-cache \ | |
freetype-dev \ | |
libjpeg-turbo-dev \ | |
libpng-dev \ | |
&& rm -rf /tmp/* | |
# Install intl extension | |
RUN apk add --no-cache \ | |
icu-dev \ | |
&& docker-php-ext-install -j$(nproc) intl \ | |
&& docker-php-ext-enable intl \ | |
&& rm -rf /tmp/* | |
# Install mbstring extension | |
RUN apk add --no-cache \ | |
oniguruma-dev \ | |
&& docker-php-ext-install mbstring \ | |
&& docker-php-ext-enable mbstring \ | |
&& rm -rf /tmp/* | |
# INstall opcache, xdebug, redis, mongodb | |
RUN docker-php-source extract \ | |
&& pecl install opcache xdebug redis mongodb apcu \ | |
&& echo "xdebug.remote_enable=on\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ | |
&& echo "xdebug.remote_autostart=on\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ | |
&& echo "xdebug.remote_port=9000\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ | |
&& echo "xdebug.remote_handler=dbgp\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ | |
&& echo "xdebug.remote_connect_back=1\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \ | |
&& docker-php-ext-enable opcache xdebug redis mongodb apcu \ | |
&& docker-php-source delete \ | |
&& rm -rf /tmp/* | |
ENTRYPOINT ['php-fpm'] |
Thanks!
/bin/sh: 1: apk: not found
Why i get error for this docker file
@alfianpurnomo-elev you using alpine?
For anyone using php:8.0-fpm
, I used this one to install mbstring
:
RUN apt-get install -y libonig-dev && docker-php-ext-install iconv mbstring
This will take care of most of what everyone is needing I think:
FROM php:7.4-fpm-alpine
# Set user to root
USER root
# Set working directory
WORKDIR /var/www/html
# Install Additional dependencies
RUN apk update && apk add --no-cache \
build-base shadow vim curl zlib libzip-dev \
libpng-dev libjpeg-turbo-dev libwebp-dev libxpm-dev zlib-dev \
openssl-dev oniguruma-dev \
icu-dev bzip2-dev freetype freetype-dev \
php7 \
php7-cli \
php7-redis \
php7-gd \
php7-common \
php7-pdo \
php7-pdo_mysql \
php7-mysqli \
php7-curl \
php7-mcrypt \
php7-intl \
php7-json \
php7-xdebug \
php7-mbstring \
php7-redis \
php7-pear \
php7-xml \
php7-phar \
php7-zip
RUN set -xe && \
cd /tmp/ && \
apk add --no-cache --update --virtual .phpize-deps $PHPIZE_DEPS
# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN docker-php-ext-install mbstring
RUN docker-php-ext-configure gd \
--with-freetype=/usr/include/ \
--with-jpeg=/usr/include/
RUN docker-php-ext-install gd
RUN docker-php-ext-install intl
RUN docker-php-ext-install zip
RUN docker-php-ext-install bz2
RUN pecl install igbinary
RUN pecl install redis
RUN docker-php-ext-enable pdo_mysql igbinary mbstring redis gd zip intl bz2
# Install PHP Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Remove Cache
RUN rm -rf /var/cache/apk/*
# Add UID '1000' to www-data
RUN usermod -u 1000 www-data
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html
# Change current user to www
USER www-data
# Update composer
RUN composer update --no-interaction
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you!