title: How to Create PHP Envirnoment in Docker?
body: <p>I am trying to dockerize <strong>php</strong> web-app with <strong>apache2</strong> server. any better way to create environment for php and apache2. I have search on internet cloud not able to find any solution.</p>
  <p>I have used ubuntu:latest as base image,I have tried to create image in step if first one work than go ahead. I have already tried to create image without php and i was succesful to run docker container but without PHP there is no meaning to run than I have take next step to add PHP into image, now I am stuck.</p>
  <p>There is image of Error below.</p>
  <p><a href="https://i.stack.imgur.com/2yyo3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2yyo3.png" alt="enter image description here" /></a></p>
  <p>Here is my Dockerfile</p>
  <pre><code>#Download base image
  FROM ubuntu:latest
  
  #Install tzdata and set timezone.
  #Update all packages run the 'apt update' command before installing any packages.
  #we need to use -y flag otherwise it will ask for yes/no?
  RUN apt-get update &amp;&amp; DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata &amp;&amp; apt-get install -y software-properties-common
  
  #Install C/C++ 
  RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test
  #RUN apt install build-essential
  RUN apt-get update -y
  RUN apt-get install -y gcc
  RUN apt-get install -y g++
  RUN ln -f -s /usr/bin/gcc /usr/bin/gcc
  RUN ln -f -s /usr/bin/g++ /usr/bin/g++
  
  RUN apt-get update -y
  RUN add-apt-repository ppa:ondrej/php
  
  # Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
  RUN apt-get update &amp;&amp; apt-get -y upgrade &amp;&amp; DEBIAN_FRONTEND=noninteractive apt-get -y install \
      apache2 php7.4 php7.4-mysql libapache2-mod-php7.4 curl lynx-common
  
  # Enable apache mods.
  RUN a2enmod php7.4
  RUN a2enmod rewrite
  
  #Remove any unnecessary files
  RUN apt-get clean
  
  #Setup Apache2 servers                                               
  #Debian configuration requires the environment variables APACHE_RUN_USER, APACHE_RUN_GROUP, and APACHE_PID_FILE to be set
  ENV APACHE_RUN_USER www-data
  ENV APACHE_RUN_GROUP www-data
  ENV APACHE_PID_FILE /var/run/apache2.pid
  ENV APACHE_LOG_DIR /var/log/apache2
  ENV APACHE_LOCK_DIR /var/lock/apache2
  
  #Expose ports
  EXPOSE 80
  
  #Change Permission
  RUN chmod -R 777 /var/www/html/
  
  #Copy files to webserver 
  COPY editor /var/www/html/
  
  # Remove Default index.html
  RUN rm /var/www/html/index.html
  
  #Start services
  CMD [&quot;/usr/sbin/apache2ctl&quot;,&quot;-D&quot;,&quot;FOREGROUND&quot;]
  </code></pre>
  <p>Thanks!!</p>