Customizing ZendPHP Apache Docker Images

ZendPHP Apache Docker images provide two mechanisms for customization, to simplify providing web server and vhost configuration. These facilities also allow you to switch to an image using a different base operating system without requiring any changes to the paths in which these configuration files are installed.

Web server configuration

You can provide Apache configuration files that configure the general web server functionality in the /entrypoint.d/httpd/ directory, using any file with a '.conf' suffix.

Enabling modules

You can provide a file named /entrypoint.d/httpd/modules, with the name of a single Apache module per line; any modules listed are enabled.

Virtual host configuration

You can provide Apache configuration files that configure the general web server functionality in the /entrypoint.d/vhost/ directory, using any file with a '.conf' suffix.

Example

For this example, we define the virtual host 'example.org', enable the heartbeat module, and configure the server name.

Our project includes the following file tree:

entrypoint.d/
  - httpd/
    - modules
    - server_name.conf
  - vhost/
    - example_org.conf

The file entrypoint.d/httpd/modules contains the following:

heartbeat

The file entrypoint.d/httpd/server_name.conf contains the following:

ServerName example.org

The file entrypoint.d/vhost/example_org.conf contains the following:

Copy
<VirtualHost *:80>
  DocumentRoot /var
  <Directory "/app">
    Options Indexes FollowSymLinks
    DirectoryIndex index.php index.html index.htm
    ReWriteEngine On
    AllowOverride All
    Require all granted
  </Directory>

  # Write logs to docker output
  ErrorLog /proc/self/fd/2
  CustomLog /proc/self/fd/2 combined
</VirtualHost> 

Our Dockerfile might look like this:

Copy
FROM cr.zend.com/zendphp/8.1:debian-11-apache

# Customizations
ARG INSTALL_COMPOSER=false
ARG ZEND_PROFILE=production
# Supply a space- or comma-separated list of additional OS packages to install
ARG SYSTEM_PACKAGES
# Supply a space- or comma-separated list of additional extensions to install
ARG ZEND_EXTENSIONS_LIST
# Supply a space- or comma-separated list of additional PECL modules to compile
ARG PECL_EXTENSIONS_LIST
# Supply a space- or comma-separated list of additional Apache modules to load/enable
ARG APACHE_MODULES
# Supply a bash script name to run after ZendPHP customizations are complete
ARG POST_BUILD_BASH

## Prepare tzdata
ENV PROFILE=$ZEND_PROFILE

## Customize PHP runtime according
## Add current directory to /var/www
COPY . /var/www

## Move the entrypoint.d subdirectory to the correct location
RUN mv /var/www/entrypoint.d /entrypoint.d

RUN ZendPHPCustomizeWithBuildArgs.sh

The following docker-compose.yml example demonstrates using the custom Dockerfile from the “Using ZendPHP via Docker” page:

Copy
version: '3.3'

services:
  php:
    build: 
      context: .
      dockerfile: Dockerfile
      args:
        OS: debian
        OS_VERSION: 11
        ZENDPHP_VERSION: 8.1
        BASE_IMAGE: apache
        ZEND_EXTENSIONS_LIST: "bcmath bz2 curl dom intl json mbstring opcache openssl simplexml xml xsl zip"
        INSTALL_COMPOSER: false
        ZEND_PROFILE: production
    ports:
      - "8080:80"
    volumes:
      - .:/app
      - ./entrypoint.d:/entrypoint.d