/easy-docker-drupal

Easy docker for drupal

Primary LanguageShell

What contains this README file

This file contain next sections:

Containers definition:

This local environment have some containers (services) that allow developers work with one or more drupal instances.

Service "mariadb"

Contain environment to load a mariadb database, which have the database stored in a persistent volume /var/lib/mysql. Internally have open the port 3306 to be available connected for rest of containers as "mariadb" host

Starting a existing Database

See https://hub.docker.com/_/mariadb for more detailed information

Service "php"

This container is the most important that have configured an Apache Server and PHP 7.3 working as "module" not as "PHP-FPM".

See https://hub.docker.com/_/drupal for more detailed information

Available ports

By defailt this container expose to host two ports:

  • 80 -> Apache HTTP request
  • 443 -> Apache HTTPS request

You must set your certtificate replacing the files that exists in conf/apache/ssl. If you do not need SSL certificate review the conf/php/virtualhost.conf to remove the VirtualHost for SSL and remove in the VirtualHost:80 the redirection to SSL

Where drupal is stored

Drupal will be stored in html folder, here you must deploy yor project and configure it in the VirtualHost setting the correct DocumentRoot path

Modifiyng the default php.ini values

You are able to change the default php.ini values, to do that you need to modify the file conf/php/php.ini and modify all necessary variables. By default some changes have been implemented to make easy the development:

  • Max execution time -> Increased from 30 to 60 seconds
  • Memory limit -> Increased from 128M to 256M
  • Max upload files -> Increased from 2M to 32M (here you must change the post_max_size and upload_max_filesize variables)

If you need enable the XDebug, you need uncomment the lines commented in the php.ini file

Accessing into container

To access into container, once the docker-compose is executed, you must launch the sentence:

docker-compose exec -u docker php bash

Default PHP version and how to change

By default this container runs with PHP 7.3, in case that you need downgrade this version you need change in the Dockerfile-drupal the first line:

FROM drupal:8-apache

For this other:

FROM drupal:7-apache

Once this lines have been changed you need rebuild the project to take effect the changes.

docker-compose up -d --build

Service "mailhog"

This service allow send dummy emails to log all of them and see the final results.

You must connect your Drupal instance using SMTP and mimemail modules with next parameters:

  • Go to the SMTP administration page: /admin/config/system/smtp and set this variables
    • SMTP: mailhog
    • Port: 1025
  • Go to the MimeMail page: /admin/config/system/mimemail and set this variables
    • Formatter: Mime Mail Mailer
    • Sender: SMTP Mailer

With this information your system is available to emulate to send emails (in HTML format) and the results you can see in http://localhost:8025

Available ports

By defailt this container expose to host one port:

  • 8025 -> Mailhog

Service "redis"

This service is a cache for Drupal. You will need install the module redis (all dependencies are built in the container).

  • Installing using composer -> composer require drupal/redis
  • Enable the module -> drush en redis

Once the module is enabled, you can add the next information in your settings.php file:

$settings['redis.connection']['interface'] = 'Predis'; // Can be "Predis".
$settings['redis.connection']['host']      = 'redis';  // Your Redis instance hostname.
$settings['redis.connection']['port']      = '6379';  // Redis port
$settings['cache']['default'] = 'cache.backend.redis';

The system automatically connect with Redis. You can see in Status report if the module works properly.

Service "solr"

This service allows index all content using Apache Solr. You will need install the module Search API Solr.

By default this service create a core called drupalsolr.

You need follow the instructions detailed in the README.md file downloaded in the module search_apoi_solr to configure properly the connection.

Available ports

By defailt this container expose to host one port:

  • 8983 -> Apache Solr request

FIRST STEPS:

  • Once you had configured the previous steps you only need this actions:

    • Initialize docker
docker-compose up -d --build
  • Go into PHP container (as root)
docker-compose exec php bash

Additionally this container have an other user to work with no root privileges, just adding -u docker:

docker-compose exec -u docker php bash

Your system is ready to work with new drupal. ENJOY!!

DEBUG your code:

This section is explained to work with Visual Studio Code...

        {
            // Use IntelliSense to learn about possible attributes.
            // Hover to view descriptions of existing attributes.
            // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
            "version": "0.2.0",
            "configurations": [
                {
                    "name": "Listen PHP Code",
                    "type": "php",
                    "request": "launch",
                    "port": 9000,
                    "stopOnEntry": true,
                    "pathMappings": {
                        "/var/www/html/": "${workspaceRoot}/drupal_dandy/",
                    }
                },
                {
                    "type": "chrome",
                    "request": "launch",
                    "name": "Listen JavaScript Code",
                    "url": "http://localhost",
                    "webRoot": "${workspaceFolder}/drupal_dandy/web"
                }
            ]
        }
  • Once your definition is finished you can go to the "Debug" section pressing F5 and select the option that you want to debug (PHP or JavaScript)

Which have this repository

This repository contains files and folders to start quickly to deploy a new drupal instance:

  • .env file -> Contains vairables definitions to connect to Drupal, project name, ... You can add all variables that you need to configure your environment. Please take account that if you want see all these variables in your container you must add this in docker-compose.yml file
  • docker-compose.yml file -> Contain the definition of all containers needed to work in your local environment
  • conf folder -> Have some configurations, mainly PHP and VirtualHost configurations
  • html folder -> Folder to store your projects.
  • Dockerfile-drupal file -> Contain all needed configuration for PHP container to establish the envirnoment to work with Drupal (PHP Modules, applications such us vim, SSH Server, ...). This image have been extended from a Docker image Drupal 8. Please referer to Docker image to see all available options.
  • README.md file -> This file

Generate id_rsa and id_rsa.pub

This step explain how to generate the files id_rsa and id_rsa.pub based on linux.

You must launch in your host the next sentence:

ssh-keygen -f conf/php/ssh/id_rsa -N ""

This files could be used to connect automatically with any Git without password, you must add the SSH-KEY conf/php/ssh/id_rsa.pub in the repository to avoid question for user and password...

Generate dummy certificate for SSL

We assume that you are located in the docroot of this document to launch this sentence:

openssl req -x509 -nodes -days 2048 -newkey rsa:2048 -keyout conf/apache/ssl/localhost.key -out conf/apache/ssl/localhost.crt