8.2.7 업데이트
This commit is contained in:
150
8.2.7/Dockerfile
Normal file
150
8.2.7/Dockerfile
Normal file
@ -0,0 +1,150 @@
|
||||
FROM php:8.2.7-apache
|
||||
|
||||
# 지속적으로 필요한 패키지 설치
|
||||
RUN set -eux; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
# Ghostscript는 PDF 미리보기 렌더링에 필요합니다.
|
||||
ghostscript \
|
||||
; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# PHP 확장 모듈 설치에 필요한 라이브러리 및 도구 설치
|
||||
RUN set -eux; \
|
||||
savedAptMark="$(apt-mark showmanual)"; \
|
||||
apt-get update; \
|
||||
apt-get install -y --no-install-recommends \
|
||||
unzip \
|
||||
libfreetype6-dev \
|
||||
libicu-dev \
|
||||
libjpeg-dev \
|
||||
libmagickwand-dev \
|
||||
libpng-dev \
|
||||
libwebp-dev \
|
||||
libzip-dev \
|
||||
libxml2-dev \
|
||||
; \
|
||||
apt-get clean; \
|
||||
\
|
||||
# gd 확장 모듈 설정 (freetype, jpeg, webp 지원)
|
||||
docker-php-ext-configure gd \
|
||||
--with-freetype \
|
||||
--with-jpeg \
|
||||
--with-webp \
|
||||
; \
|
||||
# PHP 확장 모듈 설치
|
||||
docker-php-ext-install -j "$(nproc)" \
|
||||
bcmath \
|
||||
exif \
|
||||
gd \
|
||||
intl \
|
||||
mysqli \
|
||||
zip \
|
||||
soap \
|
||||
; \
|
||||
# imagick PECL 확장 설치 및 활성화 (버전 고정)
|
||||
pecl install imagick-3.6.0; \
|
||||
docker-php-ext-enable imagick; \
|
||||
rm -r /tmp/pear; \
|
||||
\
|
||||
# 일부 확장 모듈이 표준출력에 출력하지 않는지 확인
|
||||
out="$(php -r 'exit(0);')"; [ -z "$out" ]; \
|
||||
err="$(php -r 'exit(0);' 3>&1 1>&2 2>&3)"; [ -z "$err" ]; \
|
||||
\
|
||||
extDir="$(php -r 'echo ini_get("extension_dir");')"; [ -d "$extDir" ]; \
|
||||
\
|
||||
# 설치된 확장 모듈 의존성 패키지를 수동 설치로 표시하여 제거되지 않도록 설정
|
||||
apt-mark auto '.*' > /dev/null; \
|
||||
apt-mark manual $savedAptMark; \
|
||||
ldd "$extDir"/*.so \
|
||||
| awk '/=>/ { so = $(NF-1); if (index(so, "/usr/local/") == 1) { next }; gsub("^/(usr/)?", "", so); print so }' \
|
||||
| sort -u \
|
||||
| xargs -r dpkg-query --search \
|
||||
| cut -d: -f1 \
|
||||
| sort -u \
|
||||
| xargs -rt apt-mark manual; \
|
||||
\
|
||||
# 빌드에 사용된 불필요한 패키지 자동 제거
|
||||
apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
\
|
||||
# 확장 모듈 누락 여부 점검
|
||||
! { ldd "$extDir"/*.so | grep 'not found'; }; \
|
||||
\
|
||||
# PHP 실행 시 오류 메시지 체크 (확장 모듈 로드 실패 등)
|
||||
err="$(php --version 3>&1 1>&2 2>&3)"; [ -z "$err" ]
|
||||
|
||||
# 권장 PHP 설정 (opcache 활성화 및 기본 튜닝)
|
||||
RUN set -eux; \
|
||||
docker-php-ext-enable opcache; \
|
||||
{ \
|
||||
echo 'opcache.memory_consumption=128'; \
|
||||
echo 'opcache.interned_strings_buffer=8'; \
|
||||
echo 'opcache.max_accelerated_files=4000'; \
|
||||
echo 'opcache.revalidate_freq=2'; \
|
||||
} > /usr/local/etc/php/conf.d/opcache-recommended.ini
|
||||
|
||||
# PHP 오류 로깅 설정
|
||||
# 오류는 stderr로 출력하며, 프로덕션 환경에 적합하도록 설정
|
||||
RUN { \
|
||||
echo 'error_reporting = E_ERROR | E_WARNING | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_RECOVERABLE_ERROR'; \
|
||||
echo 'display_errors = Off'; \
|
||||
echo 'display_startup_errors = Off'; \
|
||||
echo 'log_errors = On'; \
|
||||
echo 'error_log = /dev/stderr'; \
|
||||
echo 'log_errors_max_len = 1024'; \
|
||||
echo 'ignore_repeated_errors = On'; \
|
||||
echo 'ignore_repeated_source = Off'; \
|
||||
echo 'html_errors = Off'; \
|
||||
} > /usr/local/etc/php/conf.d/error-logging.ini
|
||||
|
||||
# Apache 모듈 활성화 및 설정
|
||||
RUN set -eux; \
|
||||
# URL 재작성과 캐시 만료 모듈 활성화
|
||||
a2enmod rewrite expires; \
|
||||
\
|
||||
# 클라이언트 실제 IP를 올바르게 수집하기 위한 remoteip 모듈 활성화 및 설정
|
||||
a2enmod remoteip; \
|
||||
{ \
|
||||
echo 'RemoteIPHeader X-Forwarded-For'; \
|
||||
# 사설 네트워크 IP 범위 지정 (Docker 내부 등)
|
||||
echo 'RemoteIPInternalProxy 10.0.0.0/8'; \
|
||||
echo 'RemoteIPInternalProxy 172.16.0.0/12'; \
|
||||
echo 'RemoteIPInternalProxy 192.168.0.0/16'; \
|
||||
echo 'RemoteIPInternalProxy 169.254.0.0/16'; \
|
||||
echo 'RemoteIPInternalProxy 127.0.0.0/8'; \
|
||||
} > /etc/apache2/conf-available/remoteip.conf; \
|
||||
a2enconf remoteip; \
|
||||
\
|
||||
# 로그 포맷에서 %h를 %a(IP주소)로 변경하여 프록시 환경에 맞춤
|
||||
find /etc/apache2 -type f -name '*.conf' -exec sed -ri 's/([[:space:]]*LogFormat[[:space:]]+"[^"]*)%h([^"]*")/\1%a\2/g' '{}' +
|
||||
|
||||
# Composer 설치 (설치 스크립트 해시 검증 적용)
|
||||
RUN set -eux; \
|
||||
EXPECTED_SIGNATURE="$(curl -s https://composer.github.io/installer.sig)"; \
|
||||
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"; \
|
||||
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"; \
|
||||
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]; then \
|
||||
echo 'ERROR: Invalid installer signature'; \
|
||||
rm composer-setup.php; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
php composer-setup.php --install-dir=/usr/local/bin --filename=composer; \
|
||||
rm composer-setup.php
|
||||
|
||||
# Google Cloud API용 PHP 라이브러리 설치
|
||||
RUN composer require google/cloud
|
||||
|
||||
# SimpleXLSX 라이브러리 설치 (엑셀 파싱용)
|
||||
RUN composer require shuchkin/simplexlsx
|
||||
|
||||
# 웹 루트 볼륨 지정
|
||||
VOLUME /var/www/html
|
||||
|
||||
# 엔트리포인트 스크립트 복사 및 실행 권한 부여
|
||||
COPY entrypoint.sh /usr/local/bin
|
||||
RUN chmod 755 /usr/local/bin/entrypoint.sh
|
||||
|
||||
# 엔트리포인트 및 기본 실행 명령어 지정
|
||||
ENTRYPOINT ["entrypoint.sh"]
|
||||
CMD ["apache2-foreground"]
|
||||
15
8.2.7/docker-compose.yml
Normal file
15
8.2.7/docker-compose.yml
Normal file
@ -0,0 +1,15 @@
|
||||
services:
|
||||
web:
|
||||
build: .
|
||||
image: reg.firstgarden.co.kr/php-apache:8.2.7
|
||||
container_name: php-apache
|
||||
ports:
|
||||
- "8080:80" # 호스트 8080 포트를 컨테이너 80 포트에 매핑
|
||||
environment:
|
||||
PUID: 1000 # 필요에 따라 UID 지정 (호스트 사용자 ID)
|
||||
PGID: 1000 # 필요에 따라 GID 지정 (호스트 그룹 ID)
|
||||
APACHE_RUN_USER: www-data
|
||||
APACHE_RUN_GROUP: www-data
|
||||
volumes:
|
||||
- ./html:/var/www/html # 소스코드 마운트 (호스트 ./html → 컨테이너 /var/www/html)
|
||||
restart: unless-stopped
|
||||
47
8.2.7/entrypoint.sh
Normal file
47
8.2.7/entrypoint.sh
Normal file
@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
# 환경변수 PUID가 설정되어 있으면 www-data 사용자의 UID를 변경
|
||||
if [[ -n "${PUID}" ]]
|
||||
then
|
||||
usermod -u ${PUID} www-data
|
||||
fi
|
||||
|
||||
# 환경변수 PGID가 설정되어 있으면 www-data 그룹의 GID를 변경
|
||||
if [[ -n "${PGID}" ]]
|
||||
then
|
||||
groupmod -g ${PGID} www-data
|
||||
fi
|
||||
|
||||
# 첫 번째 인자가 apache2* 또는 php-fpm이면
|
||||
if [[ "$1" == apache2* ]] || [ "$1" = 'php-fpm' ]; then
|
||||
uid="$(id -u)"
|
||||
gid="$(id -g)"
|
||||
# 현재 UID가 root이면
|
||||
if [ "$uid" = '0' ]; then
|
||||
case "$1" in
|
||||
apache2*)
|
||||
user="${APACHE_RUN_USER:-www-data}"
|
||||
group="${APACHE_RUN_GROUP:-www-data}"
|
||||
|
||||
# Apache에서 '#1000' 형식 UID/GID에서 '#' 제거
|
||||
pound='#'
|
||||
user="${user#$pound}"
|
||||
group="${group#$pound}"
|
||||
;;
|
||||
*)
|
||||
# php-fpm인 경우 기본 사용자 www-data
|
||||
user='www-data'
|
||||
group='www-data'
|
||||
;;
|
||||
esac
|
||||
else
|
||||
# root이 아니면 현재 uid/gid 그대로 사용
|
||||
user="$uid"
|
||||
group="$gid"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
# 마지막으로 인자로 받은 명령어 실행 (ex: apache2-foreground)
|
||||
exec "$@"
|
||||
Reference in New Issue
Block a user