Friday, March 3, 2023

HOW TO CREATE AN IMAGE IN PORTAINER FOR PHP8 AND APACHE TO RUN A WEB APPLICATION

Go to Image and build a New Image


Give it a name

and put this value in Web Editor portion

FROM php:8.0-apache
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
RUN apt-get update
RUN apt-get install -y \
    git \
    zip \
    curl \
    sudo \
    unzip \
    libicu-dev \
    libbz2-dev \
    libpng-dev \
    libjpeg-dev \
    libmcrypt-dev \
    libreadline-dev \
    libfreetype6-dev \
    g++

RUN docker-php-ext-install \
    bz2 \
    intl \
    bcmath \
    opcache \
    calendar \
    pdo_mysql \
    mysqli \
    gd

# 2. set up document root for apache
COPY 000-default.conf /etc/apache2/sites-available/000-default.conf

# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers

# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"

# 5. Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
RUN chmod +x /usr/local/bin/composer
RUN composer self-update


ARG phpver=8
ARG git_repo="https://gitlab+deploy-token-1823228:tRSTqEaK7dviW47zXd_zw@gitlab.com/repoAccount/repo.git"
ARG webapppath="/var/www/html/your-foldername"
ARG max_execution_time
ARG max_input_time
ARG max_input_vars
ARG memory_limit
ARG post_max_size
ARG upload_max_filesize
ARG session_maxlifetime

#Clone source code
RUN git clone $git_repo $webapppath -b develop

RUN chmod -R 755 $webapppath/writable/ 
Run chown -R www-data:www-data $webapppath/writable/ 

RUN composer update --working-dir=$webapppath

RUN cp $webapppath/env $webapppath/.env

ARG uid=1000
ENV UID=$uid

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

EXPOSE 80

===================================

Create 000-default.conf and change the value of your-foldername and upload it to Select Files button




then Build Image

  • For webapppath = edit this to your exact foldername

  • Note for ARG git_repo , if you are using gitlab. You may need to create a deploy token of your repository in able to download or clone your repository even without inputting any credential. You may check the gitlab documentation on how to create deploy token.

DONE!!
(you may now create your stack for this image for any modification, stack will create your container!)






No comments:

Post a Comment