Skip to content

Apache/PHP docker image with useful enhancements

Notifications You must be signed in to change notification settings

trenc/trenc-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

Apache/PHP docker image with useful enhancements

  • based on chialab PHP image https://github.com/chialab/docker-php
  • support for SSL
  • added mariadb-client for mysql and mysqldump binary
  • www-data with home path for certificates
  • user and group of www-data are re-created with host’s userID and groupID as workaround to file permission issues on the host (userID and groupID are set via —build-arg parameter)
  • mhsendmail as sendmail for using Mailhog https://github.com/mailhog/MailHog

Building the image

Replace USER_ID and GROUP_ID with your host IDs and the TAG you want to create from, and the set the name of the resulting image.

$ sudo docker build --build-arg USER_ID=<you-user-id-on-host> --build-arg GROUP_ID=<your-group-id-on-host> --build-arg TAG=<php-apache-version> -t <you-image-name-here> .

Example

Building an image based on chialab/php from the tag 8.0-apache. The resulting image is named sctp-php:8.0

$ sudo docker build --build-arg USER_ID=1000 --build-arg GROUP_ID=1000 --build-arg TAG=8.0-apache -t scto-php:8.0 .

Using environment variables in docker-compose.yml

Docker can make use environment variables in the .env file.

Example docker-compose.yml

web:
  image: "webapp:${TAG}"

Using environment variables in PHP docker container

If you pass the .env file in the service section in docker-compose.yml it will be passed to the environment of the docker container.

Example

.env

USER=my-user-name
PASS=my-password

docker-compose.yml

version: '3.7'

services:
  php_apache:
    image: scto-php:7.4
    volumes:
      - ./public_html/:/var/www/html/
    ports:
      - 80:80
      - 443:443
    env_file:
      - .env

And in PHP you can make use of the getenv() function

<?php

echo getenv('USER');
echo getenv('PASS');