salvamomo / docker-lamp

Debian 9, Apache 2.4, MySQL 8.0/5.7/5.6/5.5/ and PHP 7.2/7.1/7.0/5.6 for Docker. Additional tools: phpMyAdmin and MailHog

Home Page:https://www.keopx.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Native docker-based local environment for Drupal

Use this Docker compose file to spin up local environment for Drupal with a native Docker app

This docker setup works with Debian 9, Varnish 5.2/5.1/5.0/4.0, Apache 2.4, PHP 7.2/7.1/7.0/5.6, MySQL 8.0/5.7/5.6/5.5/ and Redis 4.0/3.2/3.0. This setup have Mailhog and phpMyAdmin as helper tools.

This is keopx Docker Drupal optimized images for apache-php with varnish and MySQL.


Overview

The Drupal bundle consist of the following containers:

Container Version Service name Image Public Port Enabled by default
Varnish 5.2/5.1/5.0/4.0 varnish keopx/varnish 80
Apache PHP 7.2/7.1/7.0/5.6 apache-php keopx/apache-php 8008
MySQL 8.0/5.7/5.6/5.5 mysql keopx/mysql 3306
Redis 4.0/3.2/3.0 redis keopx/redis 6379
phpMyAdmin phpmyadmin phpmyadmin/phpmyadmin 8080
Mailhog mailhog mailhog/mailhog 8025 - 1025

Instructions

Feel free to adjust volumes and ports in the compose file for your convenience.

Environment

New version works with environment variables.

You can use example.env as .env

Here list of variables:

  • Varnish version
    • VARNISH_VERSION=4.0
    • VARNISH_PORT=80
    • VARNISH_BACKEND_PORT=80
    • VARNISH_BACKEND_IP=web
    • VARNISH_MEMORY=500M
    • VARNISH_ADMIN_PORT=6082
  • APACHE with PHP - Versión de PHP {7.2|7.1|7.0|5.6}
    • WEB_PORT=8008
    • WEB_PORT_SSL=8433
    • WEB_DATA_DIR=./data/www
    • PHP_VERSION=7.1
    • PHP_SENDMAIL_PATH=/usr/sbin/ssmtp -t
    • PHP_SENDMAIL_DOMAIN=mail:1025
    • SSMTP=./config/ssmtp/ssmtp.conf
    • DRUSH=~/.drush
    • SSH=~/.ssh
  • MySQL - Versión de MySQL {8.0|5.7|5.6|5.5}
    • MYSQL_VERSION=5.7
    • MYSQL_PORT=3306
    • MYSQL_ROOT_PASSWORD=root
    • MYSQL_DATABASE=drupal
    • MYSQL_USER=drupaluser
    • MYSQL_PASSWORD=drupalpass
    • MYSQL_DATA_DIR=./data/database
  • Redis - Versión de Redis {4.0|3.2|3.0}
    • REDIS_VERSION=4.0
    • REDIS_PORT=6379
  • PhpMyadmin
    • PMA_PORT=8080
    • PMA_HOST=mysql
  • Mailhog
    • MAILHOG_PORT_SMTP=1025
    • MAILHOG_PORT_WEB=8025

Usage

Run:

$ docker-compose up -d

Stop:

$ docker-compose stop

Or down (warning: this command remove volume changes):

$ docker-compose down

Run bash

docker exec -it dockerlamp_web_1 /bin/bash

Replace dockerlamp_web_1 with name of:

docker-compose ps

Containers

Varnish

Available tags are:

Apache PHP

MySQL

Redis

phpMyAdmin

This is a default image. Only use to have a easy access to database information.

MailHog

This is a default image. Use to have easy mailsender and mail watcher to test email without send to real account.

Custom settings

Varnish

By default we can use a standard default.vcl.

In addition, you can check a varnish vcl for Drupal in drupal-base.vcl

drupal-base.vcl for Drupal

You can check a special varnish vcl file for Drupal drupal-base.vcl based in NITEMAN config file: drupal-base.vcl

Note: drupal-base.vcl uses MIT license.

If you like to add drupal-base.vcl add this lines. Added by default to 4.0 version.

    volumes:
      - ./config/varnish/4.0/drupal-base.vcl:/etc/varnish/default.vcl

4.0 version

If you need work with varnish 4.* select one file from 4.0 directoy.

    volumes:
      - ./config/varnish/4.0/opt-drupal.vcl:/etc/varnish/default.vcl

5.0 version

If you need work with varnish 5.* select 5.0 directoy file.

    volumes:
      - ./config/varnish/5.0/opt-drupal.vcl:/etc/varnish/default.vcl

Environment

The first two lines works to setup a default varnish port and memory usage limit.

The second two lines only works to change default.vcl setup to run correctly.

web is name of linked apache-php image name.

    environment:
      - VARNISH_PORT=80
      - VARNISH_MEMORY=500M
      # Next values only works with default default.vcl file.
      - VARNISH_BACKEND_IP=web
      - VARNISH_BACKEND_PORT=80

Apache PHP

Web Data Volume

    volumes:
      - ./data/www:/var/www # Data.

Apache Virtualhost

By default you can use http://localhost as working place. But if you would like a custom host to work add this changes.

You can see volumes to check existing configurations for vhosts. vhosts volume mount by default to help with setup.

    volumes:
      - ./config/vhosts:/etc/apache2/sites-enabled

Note: this example is for www.drupal8.local site.

#!bash

cp config/vhosts/example.conf.example config/vhosts/drupal8.conf
sed -i 's/example/drupal8/' config/vhosts/drupal8.conf

NOTE: review your project path.

Add to /etc/hosts new site name:

echo "127.0.0.1 drupal8.local www.drupa8.local" >> /etc/hosts

And reload system:

$ docker-compose stop
$ docker-compose up -d

PHP

Use some setup by default. You can (un)comment to change behaviour.

You can see two php.ini templates with different setup, development and production setup.

In addition, you can check apcu, opcache, xdebug and xhprof configuration, the same file for php 7.2, 7.1, 7.0 and 5.6, and opcache recomended file version for Drupal.

PHP >= 5.6 (7.0/7.1/7.2)

This example is for PHP 7.0. If you would like use PHP 7.2/7.1/5.6 change the next lines from 7.0 to 7.2/7.1/5.6.

    volumes:
      # php.ini for php 7.x and remove environment varibles.
      - ./config/php/7.0/php.ini:/etc/php/7.0/apache2/php.ini
      # Opcache for php 7.0.
      - ./config/php/opcache-recommended.ini:/etc/php/7.0/apache2/conf.d/10-opcache.ini
      # APC for php 7.0. Necessary to works APCu in PHP 7.0.
      - ./config/php/apc.ini:/etc/php/7.0/apache2/conf.d/20-apc.ini
      # APCU for php 7.0
      - ./config/php/apcu.ini:/etc/php/7.0/apache2/conf.d/20-apcu.ini
      # Xdebug for php 7.0.
      - ./config/php/xdebug.ini:/etc/php/7.0/apache2/conf.d/20-xdebug.ini
      # Xhprof for php 7.0.
      - ./config/php/xhprof.ini:/etc/php/7.0/apache2/conf.d/20-xhprof.ini

NOTE: if you like enabled APCu in PHP 7.0, you need enabled apc.ini.

e.g.: if you need add more PHP memory_limit modify ./config/php-{version}/php.ini file and reload system to works:

$ docker-compose stop
$ docker-compose up -d

Xdebug

Xdebug is enabled to debug shell command as drush.

Can read this post https://www.keopx.net/blog/debugging-drush-scripts-con-xdebug-y-phpstorm

Note: remember check docker-compose.yml to enable this feature.

Drush

If you need run some drush command to sync with some alias, to access to remote sync database or files you can uncomment next line to works into docker image.

    volumes:
      # Drush support. e.g.
      - ~/.drush:/root/.drush

SSH

If you need run some command, like a composer, to access to remote using ssh keys, you can uncomment next line to works into docker image.

    volumes:
      # SSH support. e.g.
      - ~/.ssh:/root/.ssh

Environment

WARNING: Use only if you not use custom php.ini.

You can check in docker-composer.yml two special environment variable to setup SMTP service to test local emails.

The apache-php has ssmtp sender package. Here default setup to run by default with mailhog.

Use to connect to MailHog mail instead localhost.

    environment:
      # ssmtp mail sender.
      - PHP_SENDMAIL_PATH="/usr/sbin/ssmtp -t"
      # SMTP server configruation: "domain:port" | "mail" server domain is mailhog name.
      - PHP_SENDMAIL_DOMAIN=mail:1025

Other way is adding a volume.

    volumes:
      # SSMTP support      
      - ./config/ssmtp/ssmtp.conf:/etc/ssmtp/ssmtp.conf

- ./config/ssmtp/ssmtp.conf:/etc/ssmtp/ssmtp.conf

MySQL

Use to connect to MySQl mysql instead localhost.

MySQL Data Volume

    volumes:
      - ./data/database:/var/lib/mysql

Custom my.cnf

You can check my.cnf and change you need variables.

    volumes:
      ## Custom setup for MySQL
      - ./config/mysql/my.cnf:/etc/mysql/my.cnf

Environment

  • MYSQL_ROOT_PASSWORD: The password for the root user. Defaults to a blank password.
  • MYSQL_DATABASE: A database to automatically create. If not provided, does not create a database.
  • MYSQL_USER: A user to create that has access to the database specified by MYSQL_DATABASE.
  • MYSQL_PASSWORD: The password for MYSQL_USER. Defaults to a blank password.
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=drupal
      - MYSQL_USER=drupaluser
      - MYSQL_PASSWORD=drupalpass

Redis

Use Redis for backend cache system for Drupal.

Use to connect to Redis redis instead localhost and port 6379.

phpMyAdmin

Use to connect to MySQl mysql instead localhost.

Environment

  • PMA_HOST: Host to connect phpMyAdmin.
    environment:
      - PMA_HOST=mysql

MailHog

Default image and setup.

About

Debian 9, Apache 2.4, MySQL 8.0/5.7/5.6/5.5/ and PHP 7.2/7.1/7.0/5.6 for Docker. Additional tools: phpMyAdmin and MailHog

https://www.keopx.net

License:GNU General Public License v3.0


Languages

Language:VCL 67.1%Language:PHP 32.9%