DEV Community

Cover image for Set Up PHP 8 Environment Using Docker with a Custom Dockerfile
Hòa Nguyễn Coder
Hòa Nguyễn Coder

Posted on

Set Up PHP 8 Environment Using Docker with a Custom Dockerfile

You use Docker to run PHP 8 through a custom Dockerfile. This process involves building an image from the Dockerfile, where PHP and necessary extensions are installed, then running a container based on that image to set up a PHP environment ready for development or deployment.

FROM php:8.2-fpm-alpine
ARG user
ARG uid

WORKDIR /var/www/html

RUN apk add --no-cache mysql-client msmtp perl wget procps shadow libzip libpng libjpeg-turbo libwebp freetype icu icu-data-full

RUN docker-php-ext-install pdo_mysql
RUN apk add --no-cache --virtual build-essentials \
    icu-dev icu-libs zlib-dev g++ make automake autoconf libzip-dev \
    libpng-dev libwebp-dev libjpeg-turbo-dev freetype-dev && \
    docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg --with-webp && \
    docker-php-ext-install gd && \
    docker-php-ext-install mysqli && \
    docker-php-ext-install pdo_mysql && \
    docker-php-ext-install intl && \
    docker-php-ext-install opcache && \
    docker-php-ext-install exif && \
    docker-php-ext-install zip && \
    apk del build-essentials && rm -rf /usr/src/php*

RUN wget https://getcomposer.org/composer-stable.phar -O /usr/local/bin/composer && chmod +x /usr/local/bin/composer


RUN useradd -G www-data,root -u $uid -d /home/$user $user
RUN mkdir -p /home/$user/.composer && \
    chown -R $user:$user /home/$user

COPY . /var/www/html

CMD ["php-fpm"]
Enter fullscreen mode Exit fullscreen mode

Link source from Github

👉 Youtube : Hoà Nguyễn Coder

👉 Tiktok: https://www.tiktok.com/@hoanguyencoder

👉 Twitter: https://x.com/skipperhoa

👉 Fanpage: https://www.facebook.com/profile.php?id=100049475056780

Top comments (0)