Skip to content

Instantly share code, notes, and snippets.

@DanNYSPD
Forked from Tazeg/Dockerfile
Last active August 16, 2020 17:59
Show Gist options
  • Save DanNYSPD/6f1031ea5f2a893b3b00b1ba08dd2e8d to your computer and use it in GitHub Desktop.
Save DanNYSPD/6f1031ea5f2a893b3b00b1ba08dd2e8d to your computer and use it in GitHub Desktop.
Dockerfile for a dev web server with PHP/Apache
#-----------------------------------------------------------------------
# To create the docker image :
# cd <this file directory>
# docker build -t apache-php-dev .
#
# Start image :
# docker run -d -p 80:80 -v /home/user/public_html:/var/www/html apache-php-dev
#
# Open browser :
# http://localhost
#-----------------------------------------------------------------------
FROM ubuntu:18.04
#FROM debian
LABEL maintainer="[email protected]"
LABEL description="Apache / PHP for dev"
ARG DEBIAN_FRONTEND=newt
RUN apt-get -y update && apt-get install -y \
apache2 \
php7.4 \
libapache2-mod-php7.4 \
php7.4-bcmath \
php7.4-gd \
php7.4-json \
php7.4-sqlite \
php7.4-mysql \
php7.4-curl \
php7.4-xml \
php7.4-mbstring \
php7.4-zip \
mcrypt \
nano \
vim \
git
RUN apt-get install locales
RUN locale-gen fr_FR.UTF-8
RUN locale-gen en_US.UTF-8
RUN locale-gen de_DE.UTF-8
#ENV LANG fr_FR.UTF-8
#ENV LANGUAGE fr_FR:fr
#ENV LC_ALL fr_FR.UTF-8
# config PHP
# we want a dev server which shows PHP errors
RUN sed -i -e 's/^error_reporting\s*=.*/error_reporting = E_ALL/' /etc/php/7.2/apache2/php.ini
RUN sed -i -e 's/^display_errors\s*=.*/display_errors = On/' /etc/php/7.2/apache2/php.ini
RUN sed -i -e 's/^zlib.output_compression\s*=.*/zlib.output_compression = Off/' /etc/php/7.2/apache2/php.ini
# to be able to use "nano" with shell on "docker exec -it [CONTAINER ID] bash"
ENV TERM xterm
# Apache conf
# allow .htaccess with RewriteEngine
RUN a2enmod rewrite
# to see live logs we do : docker logs -f [CONTAINER ID]
# without the following line we get "AH00558: apache2: Could not reliably determine the server's fully qualified domain name"
RUN echo "ServerName localhost" >> /etc/apache2/apache2.conf
# autorise .htaccess files
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
# for production :
# RUN echo "ServerTokens Prod\n" >> /etc/apache2/apache2.conf
# RUN echo "ServerSignature Off\n" >> /etc/apache2/apache2.conf
#RUN chown -R www-data:www-data /var/www
#RUN chmod 755 -R /var/www
RUN chgrp -R www-data /var/www
RUN find /var/www -type d -exec chmod 775 {} +
RUN find /var/www -type f -exec chmod 664 {} +
EXPOSE 80
# start Apache2 on image start
CMD ["/usr/sbin/apache2ctl","-DFOREGROUND"]
# NB : si update image and commit, do :
# docker commit -m "changes" --change "ENV TERM xterm" --change "CMD /usr/sbin/apache2ctl -DFOREGROUND" dc5239032732 apache-php-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment