Forum Navigation
You need to log in to create posts and topics.

Create HTTPD / PHP Docker – Centos 7


User wants to create docker container with httpd, PHP and various modules


Create a file called Dockerfile in the directory for the build (or download the docker file and rename to Docker without extension ) and copy this contents

FROM centos:7

# Install Apache
RUN yum -y update
RUN yum -y install httpd httpd-tools

# Install EPEL Repo
RUN rpm -Uvh \
&& rpm -Uvh

# Install PHP
RUN yum -y install php72w php72w-bcmath php72w-cli php72w-common php72w-gd php72w-intl php72w-ldap php72w-mbstring \
php72w-mysql php72w-pear php72w-soap php72w-xml php72w-xmlrpc

# Update Apache Configuration
RUN sed -E -i -e ‘/<Directory “\/var\/www\/html”>/,/<\/Directory>/s/AllowOverride None/AllowOverride All/’ /etc/httpd/conf/httpd.conf
RUN sed -E -i -e ‘s/DirectoryIndex (.*)$/DirectoryIndex index.php \1/g’ /etc/httpd/conf/httpd.conf


# Start Apache
CMD [“/usr/sbin/httpd”,”-D”,”FOREGROUND”]

Build the Docker

docker build -t image_httpd .

Run the Docker

Specify the directory with your site for the httpd server to mount as volume inside the container it will be mounted to /var/www/html  which was specified as the httpd root directory in the Docker file. the port of the container is 8080 ( just incase httpd server exists on port 80 ).

docker run -tid -p 8080:80 –name=container_httpd -v /home/website:/var/www/html image_httpd

change the value to 80:80 if you want to run as standard httpd


use your curl or your favorite browser to access the server

Uploaded files:
If you have found my website, guides, articles or videos useful, please buy me a coffee