Skip to content

Instantly share code, notes, and snippets.

@dpup
Last active January 16, 2022 18:22
Show Gist options
  • Save dpup/85e4499944ab42e54b91 to your computer and use it in GitHub Desktop.
Save dpup/85e4499944ab42e54b91 to your computer and use it in GitHub Desktop.
Apache and PHP on Docker
FROM ubuntu:latest
MAINTAINER Dan Pupius <[email protected]>
# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.0 php7.0-mysql libapache2-mod-php7.0 curl lynx-cur
# Enable apache mods.
RUN a2enmod php7.0
RUN a2enmod rewrite
# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini
# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
# Expose apache.
EXPOSE 80
# Copy this repo into place.
ADD www /var/www/site
# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUND
@EMCP
Copy link

EMCP commented Oct 15, 2014

It is no longer recommended that you put RUN apt-get update alone.. you should add a comment with the date or something similar. See https://docs.docker.com/articles/dockerfile_best-practices/

@daquinoaldo
Copy link

What kind of license you use for this file?
I would like to edit and publish again with a credit link to your original code

@cyborch
Copy link

cyborch commented Dec 27, 2018

It seems like php 7.0 isn't a part of ubuntu distribution, so Line 5 should probably be replaced with:

RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive \
    apt-get -y install software-properties-common
RUN apt-add-repository ppa:ondrej/php && apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install \
    apache2 php7.0 php7.0-mysql libapache2-mod-php7.0 curl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment