Setup for apache, php with docker
*All credited to go to * this.
2 files to setup.
- ./Dockerfile
- ./apache.conf
./Dockerfile
This can be modified to include the things you need.
Eg. RUN a2enmod headers
adds the headers modl
# Based from: https://medium.com/dev-tricks/apache-and-php-on-docker-44faef716150#.rrpzcyopr FROM ubuntu:latest MAINTAINER Simon Eames <simon.richard.eames@gmail.com> # 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 RUN a2enmod headers # 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 # Don't bother copying files. # # 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
./apache.conf
<VirtualHost *:80> ServerAdmin me@mydomain.com DocumentRoot /var/www/site <Directory /var/www/site/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order deny,allow Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
Command to follow
- Docker build.
- Run container
Build the docker container.
Build a docker container called apache-server
Run this in the same directory as the Dockerfile.
docker build -t apache-server
Run the container.
To start the container in the background.
docker run --name my-site -port 8080:80 --volume /path/to/php/site:/var/www/site --detach apache-server # or... docker run --name my-site -p 8080:80 -v /path/to/php/site:/var/www/site -d apache-server
To start the container in the forground.
docker run --interactive --tty --name my-site -port 8080:80 --volume /path/to/php/site:/var/www/site apache-server /bin/bash # or... docker run -it --name my-site -p 8080:80 -v /path/to/php/site:/var/www/site apache-server /bin/bash
docker run -it –name hedge-fund -p 8080:80 -v /c/Users/simon/projects/hedge-fund:/var/www/site apache-server /bin/bash
then start apache by hand with..
apachectl start