Skip to content

Commit

Permalink
feat(php): Php config (#57)
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Désiles <[email protected]>
  • Loading branch information
Venatum and jokesterfr authored Feb 1, 2024
1 parent 92989fc commit d174bec
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 47 deletions.
46 changes: 46 additions & 0 deletions assets/php-configuration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
set -eu

# Install PHP extensions
# @see https://olvlvl.com/2019-06-install-php-ext-source
# @see https://stackoverflow.com/a/73834081
# @see https://packages.sury.org/php/dists/

error() {
printf "\e[1;31m%s\e[0m" "${1:-Unknown error}"
exit "${2:-1}"
}

[ -z "$PHP_ENV" ] && error "PHP_ENV is not set" 2
[ -z "$PHP_VERSION" ] && error "PHP_VERSION is not set" 3

PS_PHP_EXT="gd pdo_mysql zip intl fileinfo mbstring simplexml soap bcmath"
PHP_GD_CONFIG="--with-jpeg";

if [ "7.1" = "$PHP_VERSION" ]; then
PS_PHP_EXT="$PS_PHP_EXT mcrypt";
PHP_GD_CONFIG="--with-gd --with-jpeg --with-jpeg-dir --with-zlib-dir";
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; then
PHP_GD_CONFIG="--with-jpeg-dir --with-zlib-dir";
fi

# shellcheck disable=SC2086
docker-php-ext-configure gd $PHP_GD_CONFIG
# shellcheck disable=SC2086
docker-php-ext-install $PS_PHP_EXT;

if [ "production" = "$PHP_ENV" ]; then
mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
rm -f "$PHP_INI_DIR/php.ini-development";
else
mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
rm -f "$PHP_INI_DIR/php.ini-production";
fi

# Flashlight is a testinf platform, keep things simple
sed -i 's/memory_limit = .*/memory_limit = -1/' "$PHP_INI_DIR/php.ini"
sed -i 's/upload_max_filesize = .*/upload_max_filesize = 40M/' "$PHP_INI_DIR/php.ini"
sed -i 's/post_max_size = .*/post_max_size = 40M/' "$PHP_INI_DIR/php.ini"

# Remove php assets that might have been installed by package unaware of $PHP_INI_DIR
rm -rf /etc/php* /usr/lib/php*
30 changes: 9 additions & 21 deletions docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,16 @@ ENV PHP_INI_DIR=/usr/local/etc/php
ENV COMPOSER_HOME=/var/composer

# Install base tools, PHP requirements and dev-tools
# see: https://olvlvl.com/2019-06-install-php-ext-source
ENV PHP_ENV=development
COPY ./assets/php-configuration.sh /tmp/
RUN apk --no-cache add -U \
bash less vim geoip git tzdata zip curl jq make \
nginx nginx-mod-http-headers-more nginx-mod-http-geoip \
nginx-mod-stream nginx-mod-stream-geoip ca-certificates \
gnu-libiconv php-common mariadb-client sudo \
zlib-dev libjpeg-turbo-dev libpng-dev \
zlib-dev libjpeg-turbo-dev libpng-dev oniguruma-dev \
libzip-dev icu-dev libmcrypt-dev libxml2 libxml2-dev \
&& export PS_PHP_EXT="gd pdo_mysql zip intl fileinfo simplexml" \
&& if [ "7.1" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-gd --with-jpeg --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT mcrypt; \
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT; \
else \
docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install $PS_PHP_EXT; \
fi \
&& mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini \
&& sed -i 's/memory_limit = .*/memory_limit = -1/' $PHP_INI_DIR/php.ini \
&& sed -i 's/upload_max_filesize = .*/upload_max_filesize = 40M/' $PHP_INI_DIR/php.ini \
&& sed -i 's/post_max_size = .*/post_max_size = 40M/' $PHP_INI_DIR/php.ini \
&& rm -rf /etc/php* /usr/lib/php*
&& /tmp/php-configuration.sh

# Configure php-fpm and nginx
RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \
Expand Down Expand Up @@ -87,10 +73,12 @@ ARG PS_FOLDER=/var/www/html
ADD https://github.com/PrestaShop/PrestaShop/releases/download/${PS_VERSION}/prestashop_${PS_VERSION}.zip /tmp/prestashop.zip

# Extract the souces
RUN mkdir -p $PS_FOLDER /tmp/unzip-ps \
RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \
&& unzip -n -q /tmp/prestashop.zip -d /tmp/unzip-ps \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] && unzip -n -q /tmp/unzip-ps/prestashop.zip -d $PS_FOLDER || mv /tmp/unzip-ps/prestashop/* $PS_FOLDER) \
&& chown -R www-data:www-data $PS_FOLDER \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] \
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER") \
&& chown -R www-data:www-data "$PS_FOLDER" \
&& rm -rf /tmp/prestashop.zip /tmp/unzip-ps

# Install and configure MariaDB
Expand Down
48 changes: 22 additions & 26 deletions docker/debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,33 @@ RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends -qqy \
ca-certificates bash less vim git tzdata zip unzip curl wget make jq netcat-traditional \
lsb-release libgnutls30 gnupg libiconv-hook1 \
lsb-release libgnutls30 gnupg libiconv-hook1 libonig-dev \
nginx libnginx-mod-http-headers-more-filter libnginx-mod-http-geoip \
libnginx-mod-http-geoip libnginx-mod-stream mariadb-client sudo
libnginx-mod-http-geoip libnginx-mod-stream mariadb-client sudo \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# PHP requirements and dev-tools
# see: https://olvlvl.com/2019-06-install-php-ext-source
# see: https://stackoverflow.com/a/73834081
# see: https://packages.sury.org/php/dists/
ENV PHP_ENV=development

COPY ./assets/php-configuration.sh /tmp/
RUN . /etc/os-release \
&& echo "deb [trusted=yes] https://packages.sury.org/php/ ${VERSION_CODENAME} main" > /etc/apt/sources.list.d/php.list \
&& rm /etc/apt/preferences.d/no-debian-php \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends -qqy \
php-gd libghc-zlib-dev libjpeg-dev libpng-dev libzip-dev libicu-dev libmcrypt-dev libxml2-dev \
php-gd \
libghc-zlib-dev \
libjpeg-dev \
libpng-dev \
libzip-dev \
libicu-dev \
libmcrypt-dev \
libxml2-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& export PS_PHP_EXT="gd pdo_mysql zip intl fileinfo simplexml" \
&& if [ "7.1" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-gd --with-jpeg --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT mcrypt; \
elif [ "7.2" = "$PHP_VERSION" ] || [ "7.3" = "$PHP_VERSION" ]; \
then docker-php-ext-configure gd --with-jpeg-dir --with-zlib-dir \
&& docker-php-ext-install $PS_PHP_EXT; \
else \
docker-php-ext-configure gd --with-jpeg \
&& docker-php-ext-install $PS_PHP_EXT; \
fi \
&& mv $PHP_INI_DIR/php.ini-development $PHP_INI_DIR/php.ini \
&& sed -i 's/memory_limit = .*/memory_limit = -1/' $PHP_INI_DIR/php.ini \
&& sed -i 's/upload_max_filesize = .*/upload_max_filesize = 40M/' $PHP_INI_DIR/php.ini \
&& sed -i 's/post_max_size = .*/post_max_size = 40M/' $PHP_INI_DIR/php.ini \
&& rm -rf /etc/php* /usr/lib/php*
&& /tmp/php-configuration.sh

# Configure php-fpm and nginx
RUN rm -rf /var/log/php* /etc/php*/php-fpm.conf /etc/php*/php-fpm.d \
Expand Down Expand Up @@ -86,7 +80,7 @@ RUN PHP_CS_FIXER=$(jq -r '."'"${PHP_VERSION}"'".php_cs_fixer' < /tmp/php-flavour

# Install Node.js and pnpm (yarn and npm are included)
RUN if [ "0.0.0" = "$NODE_VERSION" ]; then exit 0; fi \
&& export DEBIAN_FRONTEND=noninteractive \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update \
&& apt-get install --no-install-recommends -qqy nodejs python3 npm \
&& apt-get clean \
Expand All @@ -106,10 +100,12 @@ ARG PS_FOLDER=/var/www/html
ADD https://github.com/PrestaShop/PrestaShop/releases/download/${PS_VERSION}/prestashop_${PS_VERSION}.zip /tmp/prestashop.zip

# Extract the souces
RUN mkdir -p $PS_FOLDER /tmp/unzip-ps \
RUN mkdir -p "$PS_FOLDER" /tmp/unzip-ps \
&& unzip -n -q /tmp/prestashop.zip -d /tmp/unzip-ps \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] && unzip -n -q /tmp/unzip-ps/prestashop.zip -d $PS_FOLDER || mv /tmp/unzip-ps/prestashop/* $PS_FOLDER) \
&& chown -R www-data:www-data $PS_FOLDER \
&& ([ -f /tmp/unzip-ps/prestashop.zip ] \
&& unzip -n -q /tmp/unzip-ps/prestashop.zip -d "$PS_FOLDER" \
|| mv /tmp/unzip-ps/prestashop/* "$PS_FOLDER") \
&& chown -R www-data:www-data "$PS_FOLDER" \
&& rm -rf /tmp/prestashop.zip /tmp/unzip-ps

# Install and configure MariaDB
Expand Down

0 comments on commit d174bec

Please sign in to comment.