Skip to content

Instantly share code, notes, and snippets.

@shubhamoy
Created January 21, 2018 10:01
Show Gist options
  • Save shubhamoy/95dddfa973c3ccf23a31632893fd59ac to your computer and use it in GitHub Desktop.
Save shubhamoy/95dddfa973c3ccf23a31632893fd59ac to your computer and use it in GitHub Desktop.
Dockerfile for PHP Production
From alpine:3.4
MAINTAINER Shubhamoy - https://github.com/shubhamoy
# Timezone
ENV TIMEZONE Asia/Kolkata
ENV PHP_MEMORY_LIMIT 512M
ENV MAX_UPLOAD 50M
ENV PHP_MAX_FILE_UPLOAD 200
ENV PHP_MAX_POST 100M
ENV DUMB_INIT_VERSION 1.2.1
# install apache and php and php extensions, tzdata, wget
RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories && \
apk update && \
apk add \
apache2 \
curl wget \
tzdata \
php5-apache2 \
php5-cli \
php5-phar \
php5-zlib \
php5-zip \
php5-bz2 \
php5-ctype \
php5-mysqli \
php5-mysql \
php5-pdo_mysql \
php5-opcache \
php5-pdo \
php5-json \
php5-curl \
php5-gd \
php5-gmp \
php5-mcrypt \
php5-openssl \
php5-dom \
php5-xml \
php5-iconv
# configure timezone, apache
RUN cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && \
echo "${TIMEZONE}" > /etc/timezone && \
ln -s /usr/lib/libxml2.so.2 /usr/lib/libxml2.so && \
sed -i 's#\#LoadModule rewrite_module modules/mod_rewrite.so#LoadModule rewrite_module modules/mod_rewrite.so#' /etc/apache2/httpd.conf && \
sed -i 's#AllowOverride None#AllowOverride All#' /etc/apache2/httpd.conf && \
sed -i 's#ServerName www.example.com:80#\nServerName localhost:80#' /etc/apache2/httpd.conf && \
sed -i 's#^DocumentRoot ".*#DocumentRoot "/www/public"#g' /etc/apache2/httpd.conf && \
sed -i 's#/var/www/localhost/htdocs#/www/public#g' /etc/apache2/httpd.conf && \
sed -i "s|;*date.timezone =.*|date.timezone = ${TIMEZONE}|i" /etc/php5/php.ini && \
sed -i "s|;*memory_limit =.*|memory_limit = ${PHP_MEMORY_LIMIT}|i" /etc/php5/php.ini && \
sed -i "s|;*upload_max_filesize =.*|upload_max_filesize = ${MAX_UPLOAD}|i" /etc/php5/php.ini && \
sed -i "s|;*max_file_uploads =.*|max_file_uploads = ${PHP_MAX_FILE_UPLOAD}|i" /etc/php5/php.ini && \
sed -i "s|;*post_max_size =.*|post_max_size = ${PHP_MAX_POST}|i" /etc/php5/php.ini && \
sed -i "s|;*cgi.fix_pathinfo=.*|cgi.fix_pathinfo= 0|i" /etc/php5/php.ini && \
mkdir -p /run/apache2 && \
chown -R apache:apache /run/apache2 && \
mkdir /www && \
chown -R apache:apache /www
# Start apache
RUN echo "#!/bin/sh" > /start.sh && \
echo "httpd" >> /start.sh && \
echo "tail -f /var/log/apache2/access.log" >> /start.sh && \
chmod u+x /start.sh
# Add dumb-init
RUN wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 && \
chmod +x /usr/local/bin/dumb-init
WORKDIR /www
EXPOSE 80
ENTRYPOINT ["/usr/local/bin/dumb-init", "/start.sh"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment