Need help with docker-apache-php?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

181 Stars 123 Forks MIT License 32 Commits 1 Opened issues


Apache + PHP container image which can be linked to other containers.

Services available


Need anything else?

Contributors list

# 218,752
32 commits

Table of Contents


docker pull romeoz/docker-apache-php

or other versions (7.3, 7.2, 7.1, 7.0, 5.6, 5.5, 5.4 or 5.3):

docker pull romeoz/docker-apache-php:7.1

Alternately you can build the image yourself.

git clone
cd docker-apache-php
docker build -t="$USER/docker-apache-php" .

Quick Start

Run the application container:

docker run --name app -d -p 8080:80 romeoz/docker-apache-php

The simplest way to login to the app container is to use the

docker exec
command to attach a new process to the running container.
docker exec -it app bash


For development a volume should be mounted at


The updated run command looks like this.

docker run --name app -d -p 8080:80 \
  -v /host/to/path/app:/var/www/app/ \

This will make the development.

Linked to other container

As an example, will link with RDBMS PostgreSQL.

docker network create pg_net

docker run --name db -d romeoz/docker-postgresql

Run the application container:

docker run --name app -d -p 8080:80 \
  --net pg_net \
  -v /host/to/path/app:/var/www/app/ \

Adding PHP-extension

You can use one of two choices to install the required php-extensions:

  1. docker exec -it app bash -c 'apt-get update && apt-get install php-mongo && rm -rf /var/lib/apt/lists/*'
  2. Create your container on based the current. Сontents Dockerfile:

FROM romeoz/docker-apache-php:5.6

RUN apt-get update
&& apt-get install -y php-mongo
&& rm -rf /var/lib/apt/lists/*

WORKDIR /var/www/app/

EXPOSE 80 443

CMD ["/sbin/"]

Next step,

docker build -t php-5.6 .
docker run --name app -d -p 8080:80 php-5.6

See installed php-extension:

docker exec -it app php -m

PHP-extension "Mcrypt" was REMOVED in PHP 7.2. Use Sodium or OpenSSL


All the logs are forwarded to stdout and sterr. You have use the command

docker logs
docker logs app

Split the logs

You can then simply split the stdout & stderr of the container by piping the separate streams and send them to files:

docker logs app > stdout.log 2>stderr.log
cat stdout.log
cat stderr.log

or split stdout and error to host stdout:

docker logs app > -
docker logs app 2> -

Rotate logs

Create the file /etc/logrotate.d/docker-containers with the following text inside:

/var/lib/docker/containers/*/*.log {
    rotate 31

Optionally, you can replace

and change the number of days.

Out of the box

  • Ubuntu 12.04, 14.04, 16.04 or 18.04 LTS
  • Apache 2.4.x/2.2.x
  • PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1, 7.2 or 7.3
  • Composer (package manager)

Environment depends on the version of PHP.


Apache + PHP docker image is open-sourced software licensed under the MIT license

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.