2017 © Pedro Pelรกez
 

project drupal8-composer-template

Woprrr contributor skeleton

image

woprrr/drupal8-composer-template

Woprrr contributor skeleton

  • Friday, May 4, 2018
  • by woprrr
  • Repository
  • 8 Watchers
  • 23 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Drupal 8 Composer Skeleton

Drupal 8 skeleton dockerized in sperate containers (Nginx, PHP-FPM, MySQL and PHPMyAdmin)., (*1)

Overview

  1. Install prerequisites, (*2)

    Before installing project make sure the following prerequisites have been met., (*3)

  2. Clone the project, (*4)

    Weโ€™ll download the code from its repository on GitHub., (*5)

  3. Configure Xdebug [Optional], (*6)

    We'll configure Xdebug for IDE (PHPStorm or Netbeans)., (*7)

  4. Run the application, (*8)

    By this point weโ€™ll have all the project pieces in place., (*9)

  5. Use Makefile [Optional but strongly encouraged for beginner], (*10)

    When developing, you can use Makefile for doing recurrent operations., (*11)

  6. Use Docker Commands, (*12)

    When running, you can use docker commands for doing recurrent operations., (*13)


Install prerequisites

For now, this project has been mainly created for Unix (Linux/MacOS). Perhaps it could work on Windows., (*14)

All requisites should be available for your distribution. The most important are :, (*15)

Check if docker-compose is already installed by entering the following command :, (*16)

which docker-compose

Check Docker Compose compatibility :, (*17)

The following is optional but makes life better :, (*18)

which make

Images to use

You should be careful when installing third party web servers such as MySQL or Nginx., (*19)

This project use the following ports :, (*20)

Server Port
MySQL 8989
PHPMyAdmin 8080
Nginx 8000
Nginx SSL 3000

Clone the project

To install Git, download it and install following the instructions :, (*21)

git clone -b drupal8-skeleton-docker git@github.com:woprrr/drupal8-composer-template.git

Go to the project directory :, (*22)

cd drupal8-composer-template

Project tree

.
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ app
โ”‚ย ย  โ””โ”€โ”€ Drupal
โ”‚ย ย      โ””โ”€โ”€ parameters.yml.dist
โ”œโ”€โ”€ composer.json.dist
โ”œโ”€โ”€ composer.require.json
โ”œโ”€โ”€ composer.required.json.dist
โ”œโ”€โ”€ composer.suggested.json.dist
โ”œโ”€โ”€ config
โ”œโ”€โ”€ data
โ”‚ย ย  โ””โ”€โ”€ db
โ”‚ย ย      โ”œโ”€โ”€ dumps
โ”‚ย ย      โ””โ”€โ”€ mysql
โ”œโ”€โ”€ doc
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ etc
โ”‚ย ย  โ”œโ”€โ”€ nginx
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ default.conf
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ default.template.conf
โ”‚ย ย  โ”œโ”€โ”€ php
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ php.ini
โ”‚ย ย  โ””โ”€โ”€ ssl
โ”œโ”€โ”€ scripts
โ”‚ย ย  โ””โ”€โ”€ Composer
โ”‚ย ย      โ”œโ”€โ”€ DrupalExportConf.php
โ”‚ย ย      โ”œโ”€โ”€ DrupalHandlerBase.php
โ”‚ย ย      โ”œโ”€โ”€ DrupalInstall.php
โ”‚ย ย      โ””โ”€โ”€ DrupalUpdate.php
โ””โ”€โ”€ settings
    โ”œโ”€โ”€ development.services.yml.dist
    โ”œโ”€โ”€ phpunit.xml.dist
    โ”œโ”€โ”€ services.yml
    โ”œโ”€โ”€ settings.local.php.dist
    โ””โ”€โ”€ settings.php

Configure Xdebug

If you use another IDE than PHPStorm or Netbeans, go to the remote debugging section of Xdebug documentation., (*23)

For a better integration of Docker to PHPStorm, use the documentation., (*24)

  1. Get your own local IP address :, (*25)

    sudo ifconfig
    
  2. Edit php file etc/php/php.ini and comment or uncomment the configuration as needed., (*26)

  3. Set the remote_host parameter with your IP :, (*27)

    xdebug.remote_host=192.168.0.1 # your IP
    

Run the application

  1. Setup project environment variables :, (*28)

    Setup your project by editing the .env file and customize all environement variables. Specifically all Drupal_* variable are criticaly important to next steps and to customize your drupal instances., (*29)

  2. Initialize/Install project dependencies :, (*30)

    make docker-start
    

    Please wait this might take a several minutes..., (*31)

    sudo docker-compose logs -f # Follow log output
    
  3. Install Drupal instance :, (*32)

    make drupal-si
    

    Or specify name of configuration instance, (*33)

    make drupal-si my_configuration_name
    

    All of configuration available are defined in your settings/settings.local.php file from, (*34)

    # Config directories
    $config_directories = array(
      my_configuration_name => '/absolute/path/to/config'
    );
    

    Example of typical workflow with configuration, (*35)

    # Config directories
    $config_directories = array(
      dev => getcwd() . '/../config/dev',
      preprod => getcwd() . '/../config/preprod',
      prod => getcwd() . '/../config/prod',
      stage => getcwd() . '/../config/stage',
    );
    
  4. Open your favorite browser :, (*36)

  5. Stop and clear services :, (*37)

    sudo docker-compose down -v
    
  6. Stop and delete all traces of changes from skeleton :, (*38)

    sudo make docker-stop
    

    That delete all files to reset skeleton at his initial state., (*39)

Play with Drupal Configuration workflow

  1. Export your current configuration instance, (*40)

    make drupal-config-export
    

    Or with Docker Compose, (*41)

    docker-compose exec -T php composer export-conf
    
  2. After your first install of Drupal instance edit the .env file and change the following variable DRUPAL_INSTALL_PROFILE=standard to DRUPAL_INSTALL_PROFILE=config_installer. That take ability to re-install / update your drupal instance with ./config/* exported configuration states., (*42)

  3. Re-install or update your instance from exported configuration, (*43)

    Re-install: With Drop of current drupal database and complete re-import of ./config sh make drupal-si, (*44)

    Update: With following drupal commands (up-db / ent-up )., (*45)

    Every action processed by scripts switch your Drupal instance on maintenance mode and switch Online after every action automatically., (*46)

    make drupal-update
    
  4. In more advanced usage you can also specified a drupal configuration name, (*47)

    make drupal-si preprod || make drupal-update preprod
    

    Or with Docker Compose, (*48)

    docker-compose exec -T php composer site-install preprod ||ย docker-compose exec -T php composer site-update preprod
    

Examples of life cycle

  1. Start the Project containers :, (*49)

    sudo make docker-start
    
  2. Edit .env file., (*50)

  3. Install drupal 8 instance :, (*51)

    sudo make docker-si
    
  4. Exporting Drupal configuration files :, (*52)

    ```sh
    make drupal-config-export
    ```
    **Or with a specific destination**
    ```sh
    make drupal-config-export my_configuration_name
    ```
  5. Enable Re-install from configuration mode : Edit .env file by changing DRUPAL_INSTALL_PROFILE=standard to DRUPAL_INSTALL_PROFILE=config_installer., (*53)

  6. Re-installation of project from exported configuration : sh make drupal-si, (*54)

  7. Update of current instance : Edit one of configuration yml in your /config folder eg: system.site.site_name. and process to updating your drupal instance from configuration by using, (*55)

    ```sh
    make drupal-update
    ```

    Your Site Name will change that you specified in system.site.site_name yml file., (*56)

  8. Another tips ? Call Help ;) : Show help :, (*57)

    make help
    

Use Makefile

When developing, you can use Makefile for doing the following operations :, (*58)

| Name | Description | |----------------------|-------------------------------------------------------------------------------------------------------------------------| | code-sniff | Check the API with PHP Code Sniffer (Drupal Standards). | | clean | Clean directories for reset. | | c-install | Install PHP/Drupal dependencies with composer. | | c-update | Update PHP/Drupal dependencies with composer. | | clean-drupal-config | Delete exported configuration from project. | | docker-start | Create and start containers. | | docker-stop | Stop and clear all services. | | gen-certs | Generate SSL certificates. | | logs | Follow log output | | mysql-dump | Create backup of all databases | | mysql-restore | Restore backup of all databases | | test | Test all application (custom and contribution modules). | | test-contrib | Test application with phpunit | | test-custom-modules | Test Drupal custom modules. | | drupal-si | Install new Drupal instance and drop database. | | drupal-update | Update your current Drupal instance and (re)import your `/config` exported configuration. | | drupal-config-export | Export your current Drupal instance from `/config` by default. That can be in sub-folder depend your custom changes. |, (*59)


Use Docker commands

Installing package with composer

docker-compose exec -T php composer install

Requiring package with composer

docker-compose exec -T php composer require drupal/core

Updating PHP dependencies with composer

docker-compose exec -T php composer update

Testing PHP application with PHPUnit

docker-compose exec -T php bin/phpunit -c ./web/core ./web

Fixing standard code with CODER

docker-compose exec -T php composer phpcs ./web/modules/ or specify more specific path.

Checking the standard code with CODER

sudo docker-compose exec -T php ./app/vendor/bin/phpcs -v --standard=PSR2 ./app/src

Checking installed PHP extensions

sudo docker-compose exec php php -m

Handling database

MySQL shell access

sudo docker exec -it mysql bash

and, (*60)

mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD"

Creating a backup of all databases

mkdir -p data/db/dumps
source .env && sudo docker exec $(sudo docker-compose ps -q mysqldb) mysqldump --all-databases -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" > "data/db/dumps/db.sql"

Restoring a backup of all databases

source .env && sudo docker exec -i $(sudo docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/db.sql"

Creating a backup of single database

Notice: Replace "YOUR_DB_NAME" by your custom name., (*61)

source .env && sudo docker exec $(sudo docker-compose ps -q mysqldb) mysqldump -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" --databases YOUR_DB_NAME > "data/db/dumps/YOUR_DB_NAME_dump.sql"

Restoring a backup of single database

source .env && sudo docker exec -i $(sudo docker-compose ps -q mysqldb) mysql -u"$MYSQL_ROOT_USER" -p"$MYSQL_ROOT_PASSWORD" < "data/db/dumps/YOUR_DB_NAME_dump.sql"

Connecting MySQL from PDO

<?php
    try {
        $dsn = 'mysql:host=mysql;dbname=test;charset=utf8;port=3306';
        $pdo = new PDO($dsn, 'dev', 'dev');
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
?>

Or using Drush to check if your database configuration is OK, (*62)

    docker-compose exec -T php bin/drush --root="/var/www/html/web" sql-connect

Help us

Any thought, feedback or (hopefully not!), (*63)

The Versions

02/05 2018
09/04 2018

8.2.x-dev

8.2.9999999.9999999-dev

A complex template for Drupal 8 with composer management.

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

by Alexandre MALLET
by Alexandre Mallet (woprrr)

05/01 2017

8.1.0.x-dev

8.1.0.9999999-dev

An project architecture of Drupal 8

  Sources   Download

GPL-2.0+

The Requires

  • composer/installers ^1.0.20
  • drupal/core 8.3.x-dev
  • drush/drush 8.x
  • drupal/console dev-master
  • drupal/devel 1.0.0-alpha1
  • drupal/allowed_formats 1.0.0
  • drupal/ctools 3.0.0-alpha27
  • drupal/embed 1.0.0-rc3
  • drupal/entity_embed 1.0.0-beta1
  • drupal/extlink 1.0.0-alpha3
  • drupal/field_group 1.0.0-rc4
  • drupal/file_entity 2.0.0-beta2
  • drupal/imagick 1.x-dev
  • drupal/inline_entity_form 1.0.0-alpha6
  • drupal/media_entity 1.5.0
  • drupal/media_entity_image 1.2.0
  • drupal/paragraphs ^1.0
  • drupal/search_api 1.0.0-beta2
  • drupal/restui 1.11.0
  • drupal/toolbar_menu 1.3.0
  • drupal/admin_toolbar 1.17.0
  • drupal/pathauto 1.0.0-beta1
  • drupal/entity_browser 1.0.0-alpha9
  • drupal/token 1.0.0-beta2
  • drupal/libraries 3.x-dev
  • phpunit/phpunit ~4.8

 

by Alexandre MALLET