Skip to content
Docker image for LAP stack - Alpine + Apache2 + PHP7
Shell Dockerfile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
Dockerfile
LICENSE
README.md
docker-compose.yml.example
entrypoint.sh

README.md

Alpine-based LAP Server with PHP extensions

Provides a basic LAP stack using stable Alpine, Apache2 and PHP7 (version from stable repository of Alpine), loading in the various extensions along the way (see Dockerfile for full list).

Should allow you to get going with a full LAP stack and support for DB via linked container (such as mysql) with ease, allowing you to fine tune various aspects of the server and php via environment variables.

This project is partially taken from here, but with some stabilization patches (all packages installed only from stable branch of Alpine repository).

List of packages included in this image

bash, apache2, php7, php7-apache2, git, tzdata, openntpd, nano, curl, ca-certificates, openssl, openssh-keygen, openssh-client

php7-phar, php7-mcrypt, php7-soap, php7-openssl, php7-gmp, php7-pdo_odbc, php7-json, php7-dom, php7-pdo, php7-zip, php7-mysqli, php7-sqlite3, php7-pdo_pgsql, php7-bcmath, php7-gd, php7-odbc, php7-pdo_mysql, php7-pdo_sqlite, php7-gettext, php7-xmlreader, php7-xmlrpc, php7-bz2, php7-iconv, php7-pdo_dblib, php7-curl, php7-ctype, php7-session, php7-redis, php7-fileinfo

List of all available environment variables

Various env vars can be set at runtime via your docker command or docker-compose environment section:

APACHE_SERVER_NAME: Change server name to match your domain name in httpd.conf

PHP_SHORT_OPEN_TAG: Maps to php.ini 'short_open_tag'

PHP_OUTPUT_BUFFERING: Maps to php.ini 'output_buffering'

PHP_OPEN_BASEDIR: Maps to php.ini 'open_basedir'

PHP_MAX_EXECUTION_TIME: Maps to php.ini 'max_execution_time'

PHP_MAX_INPUT_TIME: Maps to php.ini 'max_input_time'

PHP_MAX_INPUT_VARS: Maps to php.ini 'max_input_vars'

PHP_MEMORY_LIMIT: Maps to php.ini 'memory_limit'

PHP_ERROR_REPORTING: Maps to php.ini 'error_reporting'

PHP_DISPLAY_ERRORS: Maps to php.ini 'display_errors'

PHP_DISPLAY_STARTUP_ERRORS: Maps to php.ini 'display_startup_errors'

PHP_LOG_ERRORS: Maps to php.ini 'log_errors'

PHP_LOG_ERRORS_MAX_LEN: Maps to php.ini 'log_errors_max_len'

PHP_IGNORE_REPEATED_ERRORS: Maps to php.ini 'ignore_repeated_errors'

PHP_REPORT_MEMLEAKS: Maps to php.ini 'report_memleaks'

PHP_HTML_ERRORS: Maps to php.ini 'html_errors'

PHP_ERROR_LOG: Maps to php.ini 'error_log'

PHP_POST_MAX_SIZE: Maps to php.ini 'post_max_size'

PHP_DEFAULT_MIMETYPE: Maps to php.ini 'default_mimetype'

PHP_DEFAULT_CHARSET: Maps to php.ini 'default_charset'

PHP_FILE_UPLOADS: Maps to php.ini 'file_uploads'

PHP_UPLOAD_TMP_DIR: Maps to php.ini 'upload_tmp_dir'

PHP_UPLOAD_MAX_FILESIZE: Maps to php.ini 'upload_max_filesize'

PHP_MAX_FILE_UPLOADS: Maps to php.ini 'max_file_uploads'

PHP_ALLOW_URL_FOPEN: Maps to php.ini 'allow_url_fopen'

PHP_ALLOW_URL_INCLUDE: Maps to php.ini 'allow_url_include'

PHP_DEFAULT_SOCKET_TIMEOUT: Maps to php.ini 'default_socket_timeout'

PHP_DATE_TIMEZONE: Maps to php.ini 'date.timezone'

PHP_PDO_MYSQL_CACHE_SIZE: Maps to php.ini 'pdo_mysql.cache_size'

PHP_PDO_MYSQL_DEFAULT_SOCKET: Maps to php.ini 'pdo_mysql.default_socket'

PHP_SESSION_SAVE_HANDLER: Maps to php.ini 'session.save_handler'

PHP_SESSION_SAVE_PATH: Maps to php.ini 'session.save_path'

PHP_SESSION_USE_STRICT_MODE: Maps to php.ini 'session.use_strict_mode'

PHP_SESSION_USE_COOKIES: Maps to php.ini 'session.use_cookies'

PHP_SESSION_COOKIE_SECURE: Maps to php.ini 'session.cookie_secure'

PHP_SESSION_NAME: Maps to php.ini 'session.name'

PHP_SESSION_COOKIE_LIFETIME: Maps to php.ini 'session.cookie_lifetime'

PHP_SESSION_COOKIE_PATH: Maps to php.ini 'session.cookie_path'

PHP_SESSION_COOKIE_DOMAIN: Maps to php.ini 'session.cookie_domain'

PHP_SESSION_COOKIE_HTTPONLY: Maps to php.ini 'session.cookie_httponly'

PHP_XDEBUG_ENABLED: Turns on xdebug (which is not for production really)

Usage

Docker Compose

You can create a docker-compose.yml file to keep things nice and simple:

version: "3"

services:

  mariadb:
    restart: unless-stopped
    image: mariadb:10
    ports:
    # Database port, will be mapped to localhost interface only
    - 127.0.0.1:3308:3306
    volumes:
    # Path to folder of local filesystem with database files
    - ./databases/mariadb:/var/lib/mysql
    environment:
    # Parameters which will be used in application
    - MYSQL_ROOT_PASSWORD=ive_got_no_roots
    - MYSQL_ROOT_HOST=%
    - MYSQL_DATABASE=somedatabase
    - MYSQL_USER=user
    - MYSQL_PASSWORD=user_pass

  application:
    image: evilfreelancer/alpine-apache-php7
    environment:
    # Database parameters of app
    - DB_HOST=mariadb
    - DB_NAME=somedatabase
    - DB_USER=user
    - DB_PASS=user_pass
    # Settings of php.ini
    - PHP_SHORT_OPEN_TAG=On
    - PHP_ERROR_REPORTING=E_ALL
    - PHP_DISPLAY_ERRORS=On
    - PHP_HTML_ERRORS=On
    - PHP_XDEBUG_ENABLED=true
    ports:
    # Web-server HTTP port, will be mapped to all network interfaces
    - 80:80
    volumes:
    # Folder in which will be "public" folder with index.php
    # and other sources of application
    - ./application:/app

Where:

  • mariadb - Is a container with SQL database
  • application - Container based on evilfreelancer/alpine-apache-php7 image with your application

In folder ./application will be your application, it should have ./application/public subfolder with index.php because this container is will use /app/public path as webroot of Apache.

Then run command below, it will start composition of containers:

docker-compose up -d

Docker

If you would like to add some files into this container then you can create your own Dockerfile based on this image:

FROM evilfreelancer/alpine-apache-php7

ADD ["./public", "/app/public"]
RUN composer update --working-dir=/app/public \
 && chown -R apache:apache /app

Probably you want to install some packages via NPM by NodeJS:

FROM evilfreelancer/alpine-apache-php7

ADD [".", "/app"]
WORKDIR /app

RUN apk update \
 && apk add --update --no-cache nodejs nodejs-npm \
 && npm install \
 && composer update \
 && chown -R apache:apache /app

If you want install some additional extension which not already installed:

FROM evilfreelancer/alpine-apache-php7

ADD [".", "/app"]
WORKDIR /app

RUN apk update \
 && apk add --update --no-cache php7-amqp \
 && composer update --working-dir=/app \
 && chown -R apache:apache /app

Where do I put my files?

You can place them in the /app folder, but your main index.php file must be in /app/public. This allows you to have your src files and other outside the public directory.

Important folders and files inside container

  • Apache WebRoot - /app/public/
  • Apache Configs - /etc/apache2/
  • Apache Logs - /var/log/apache2/
  • Composer - /usr/local/bin/composer
  • PHP.ini - /etc/php7/php.ini
You can’t perform that action at this time.