customize ddev for TYPO3

ddev is an extension to a normal docker setup which is very useful for the development of TYPO3 projects and offers a very good speed.

For the standard installation there are good instructions at :
typo3.org
ddev installation
ddev TYPO3 Quickstart

This offers automatic project URLs, https certificates with mkcert, high performance and customizability and much more. This article is about special customizations for TYPO3. In 2019 ddev became more interesting in two areas for use with TYPO3 In version 1.10.0 configurable commands were added and in version 1.12.0 much more selectable database versions.

customize config.yaml

APIVersion: v1.12.2
name: ddev-typo3
type: typo3
docroot: public
php_version: "7.2"
webserver_type: apache-fpm
dbaimage: phpmyadmin/phpmyadmin:4.9.4
router_http_port: "80"
router_https_port: "443"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
mysql_version: "5.7"
nfs_mount_enabled: true
provider: default
hooks:
  post-start:
  - exec: echo '*/1 * * * * root TYPO3_CONTEXT=Development/Local /usr/bin/php /var/www/html/public/typo3/sysext/core/bin/typo3
      scheduler:run' | sudo tee -a /etc/cron.d/typo3
  - exec: sudo chmod 0600 /etc/cron.d/typo3 && sudo service cron start
webimage_extra_packages: [cron]
use_dns_when_possible: true
timezone: Europe/Berlin

I usually set the webserver_type to apache-fpm because nginx does not support .htaccess files. The dbaimage can be set to phpmyadmin/phpmyadmin:4.9.4 since ddev 1.12.*. That sounds unspectacular but since phpmyadmin 4.8 the collation of all tables can be changed in one step and the original ddev dbaimage only contains version 4.7. Despite the changed image the dddev routing functions work and I can reach phpmyadmin at the project address on port 8036.
nfs_mount_enabled is set to true in general, becausevit improve the response times of TYPO3. hooks and webimage_extra_packages are set to work with the TYPO3 Scheduler. With webimage_extra_packages you can also install other packages like graphicsmagick.
webimage_extra_packages: [cron, graphicsmagick]
For reasonable time settings I set timezone to Europe/Berlin.
Since version 1.12 the php versions are from 5.6 to 7.4, the mariadb versions from 5.5 to 10.4 and mysql versions from 5.5 to 8.0 are available in the basic project.

docker-compose.override.yaml

version: '3.6'

services:
web:
environment:
- TYPO3_CONTEXT=Development/Local
- PHP_IDE_CONFIG=serverName=${DDEV_SITENAME}.ddev.site
volumes:
# add php xdebug profile path
- ./php-profiles/:/tmp/debug/:delegated
# ports:
# - 8899:80

Here the TYPO3_CONTEXT can be set. With PHP_IDE_CONFIG=serverName=*** the server name for Phpstorm xdbug can be set.
Under volumes the folder for xdebug profiling is specified. The commented out port can be used for testing TYPO3 on different devices/browsers (###host-ip####:8899).

Homeadditions

If you spend a lot of time on the console in the container, adjustments are helpful. The easiest way is to rename the file bash_aliases.example in the homeadditions folder to .bash_aliases. Who, like me, likes the zsh shell, can follow these instructions.
In this folder you can also create a .ssh folder with keys and config. Please don't forget to include it in the .gitignore file wink

Php Settings

In the folder .ddev/php own php settings can be set. I have put a 99-override.ini here. The 99 is to really overwrite the settings.

; Zend OPCache
opcache.enable = 1
opcache.memory_consumption = 256M
opcache.interned_strings_buffer = 16
opcache.max_accelerated_files = 10000
opcache.fast_shutdown = 1
opcache.enable_cli = 1
opcache.revalidate_freq = 0

;APCu Support
apc.shm_size = 128M

; XDebug
xdebug.remote_enable = 1
xdebug.remote_autostart = 0
xdebug.remote_connect_back = 0
xdebug.remote_host = host.docker.internal
xdebug.idekey = "PHPSTORM"

xdebug.cli_color = 1
xdebug.max_nesting_level = 1000

xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_dir = '/tmp/debug'

Recommended settings for caches and debugging are changed. The Apcu Cache Size is normally set to 32MB. Since APCu is much more common on servers than Redis, I use it quite often and sometimes need more memory for some projects. For xdebug I found it quite useful to disable the autostart function.

Customizable console Commands

Since ddev version 1.10.* it is possible to create own commands. Under .ddev/commands there is a folder for each of the standard containers, such as db or web. Commands in the host folder are executed on your computer, those in the other folders in the respective container. In each folder there are example scripts and a readme with explanations and a list of Env variables that can be used in the bash scripts. In the commands all possibilities of a normal shell script can be used. Here are a few examples:

host folder

db-backup

#!/bin/bash

## Description: Backup db
## Usage: db-backup
## Example: "ddev db-backup"

ddev exec mkdir -p ./.ddev/backup

ddev exec rm -f ./.ddev/backup/mysql-db.sql.gz

ddev export-db -f ./.ddev/backup/mysql-db.sql.gz

db-restore

#!/bin/bash

## Description: Restore db
## Usage: db-restore
## Example: "ddev db-restore"

ddev import-db --src=./.ddev/backup/mysql-db.sql.gz

ddev typo3cms cleanup:updatereferenceindex

The commented lines are used by ddev to display help on the command. "## Usage:" is a bit special, if it does not contain the filename, it will give an error message when executing. Whenever possible I use commands that are executed in the container, so there is more independence from the host operating system.

open

#!/bin/bash

## Description: Open a browser with the current site Backend
## Usage: open
## Example: "ddev open"

BROWSER='Firefox Developer Edition'

open -a "${BROWSER}" ${DDEV_PRIMARY_URL}/typo3

This is a modification of the existing launch command, which immediately opens the TYPO3 backend in my preferred browser.

warmup-dev

#!/usr/bin/env bash

## Description: Cache warmup with sitemap.xml
## Usage: warmup-dev
## Example: "ddev warmup-de"

domains=(
ddev-typo3.ddev.site
)

function get {
wget -q --no-check-certificate $1/sitemap.xml --no-cache -O - | egrep -o "$1[^<]+" | while read subsite;
do
subsite=$(echo $subsite | sed 's/\&amp;/\&/g')
echo --- Reading Sub: $subsite ---
wget -q --no-check-certificate $subsite --no-cache -O - | egrep -o "$1[^<]+" | while read line;
do
line=$(echo $line | sed 's/\&amp;/\&/g')
time curl -sL -A 'Cache Warmer' $line > /dev/null 2>&1
echo $line:
done
echo --- FINISHED reading sub-sitemap: $subsite: ---
done
}

for domain in "${domains[@]}" ; do
echo "$domain"
get $domain
done

Loads all pages of the sitemap.xml which can be activated in TYPO3 9.x. This is a simple variant to build up the cache or to recalculate all images.

web folder

These commands are executed in the Server Container.

t3logs

#!/bin/bash

## Description: show TYPO3 logs
## Usage: t3logs
## Example: "ddev t3logs"

tail -F /var/www/html/var/log/* >> /dev/stderr

The TYPO3 log is continuously displayed in the terminal.

typo3

#!/bin/bash

## Description: run typo3 cli
## Usage: typo3
## Example: "ddev typo3"

TYPO3_CONTEXT=Development/Local ./vendor/bin/typo3 $@

Without parameters all console commands provided by the TYPO3 core are listed. These can be passed as parameters and executed.
z. e. g. "ddev typo3 referenceindex:update"

typo3cms

#!/bin/bash

## Description: run typo3cms (typo3 console) in cli
## Usage: typo3cms
## Example: "ddev typo3cms"

TYPO3_CONTEXT=Development/Local ./vendor/bin/typo3cms $@

Works like the typo3 command for the extension typo3-console.
ddev typo3cms cache:flush
If no TYPO3 is running in the container, it is possible to execute e.g. Symfony console commands.

t3cache

#!/bin/bash

## Description: run typo3cms cache:flush
## Usage: t3cache
## Example: "ddev t3cache"

if [[ $1 = "debug" ]]; then
PHP_IDE_CONFIG=serverName=ddev-typo3.ddev.site XDEBUG_CONFIG=idekey=PHPSTORM TYPO3_CONTEXT=Development/Local ./vendor/bin/typo3cms cache:flush
else
TYPO3_CONTEXT=Development/Local ./vendor/bin/typo3cms cache:flush
fi

Is an example of how commands can be executed using a parameter, e.g. in debug mode. This is especially useful when testing your own commands.

Artikel Suchen