Docker Container: Centos 7, Apache, and PHP 5.5

August 5, 2019

In a previous post we created a Docker Container with Apache and PHP.
In that instance we used a recent version of PHP.

However, if what you need is to run some legacy PHP code, you would need to create a container with an older version of PHP, which is what we are going to do on this post.


We are going to create container with PHP 5.5.

Dockerfile

Open a text editor and paste the following content on it. Save it with the name Dockerfile.


FROM centos:7

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

# Install EPEL Repo
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm \
 && rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

# Install PHP 5.5
RUN yum -y install php55w php55w-bcmath php55w-cli php55w-common php55w-gd php55w-intl php55w-ldap php55w-mbstring \
    php55w-mcrypt php55w-mysql php55w-pdo php55w-pear php55w-soap php55w-xml php55w-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

EXPOSE 80

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

You can also download this Dockerfile here


• Compared to the Dockerfile on a previous post, the difference is that we have installed the php55w libraries from the EPEL repository.
• You may notice that we have also included some php libraries that are currently deprecated, such as php55w-mbstring, which were active at that time.


Create the Docker Image and Container

Now we create the Docker Image.


docker build -t image_apache .

Then we create the Docker Container.

Notice that we need to indicate the path of our local folder that will be served as the root of the Apache Web Server, which in this example is /path_to/my_website. Replace it with the location of your site's root folder..


docker run -tid -p 4000:80 --name=container_apache -v /path_to/my_website:/var/www/html image_apache

After the Docker Container is created, go to the url http://localhost:4000 to open the local website.


Downloads

Dockerfile