Direkt zum Inhalt

Devbits

Kleine Code-Schnipsel aus unserem Alltag mit Drupal, PHP und DevOps: Problem, Lösung, Code.

11.11.2026 | Marc Hitscherich

Git flow hotfix without release tag

By default, git flow hotfix finish creates a release tag. Small fixes, such as config changes or typos, don't always need a new version, but they still need to land in main and develop.

git flow hotfix start fix-short-description
# ... commit changes ...
git flow hotfix finish fix-short-description -n -p

Issue:

By default, git flow hotfix finish creates a release tag. Small fixes, such as config changes or typos, don't always need a new version, but they still need to land in main and develop.

Prerequisites:

git-flow (AVH Edition) is installed and the repository is initialized with git flow init. Ensure that your local main and develop branches are up to date.

Solution:

The -n (--notag) flag finishes the hotfix without creating a tag. The hotfix branch is merged into main and develop and then deleted. The -p (--push) flag then pushes main and develop to origin.

12.03.2026 | Pascal Crott, Michael Böker

Convert MySQL 8 Database Dump to MariaDB

You have a MySQL 8 Database Dump which needs to be converted into MariaDB for use with a Drupal setup.

cat olddump.sql | sed -e s/uca1400_as_ci/utf8mb4_general_ci/ | gzip > newdump.sql.gz

Issue

You have a MySQL 8 Database Dump which needs to be converted into MariaDB for use with a Drupal setup.

Solution

Use the command provided.

22.01.2026 | Marc Hitscherich

Fix SSH warning "Remote host identification has changed" after server move.

If you have moved to a new server and want to access it with SSH via domain name, you will get the warning "Remote host identification has changed" due to changed SSH fingerprints in your `~/.ssh/known_host` file.

# Remove all old entries for my.example.com
ssh-keygen -R my.example.com

# Scan all supported fingerprints from the new server and insert them in your known_hosts file
ssh-keyscan my.example.com >> ~/.ssh/known_hosts

Issue:

If you have moved to a new server and want to access it with SSH via domain name, you will get the warning "Remote host identification has changed" due to changed SSH fingerprints in your `~/.ssh/known_host` file.

The code snippet addresses the challenge of updating SSH fingerprints in the known_hosts file for a server, particularly in cases where the server's keys have been changed, or there are discrepancies with the existing entries.

Solution:

Remove all old entries from the `~/.ssh/known_host` file and insert the new fingerprint(s). Hint: Only do this if you are sure that the new server is under your control.

This code snippet provides a solution to update the SSH fingerprints in the known_hosts file. It first removes any old entries related to a specific hostname (my.example.com) using the ssh-keygen command with the -R option. Then, it scans and appends all supported fingerprints from the new server to the known_hosts file using the ssh-keyscan command.

13.11.2025 | Marc Hitscherich

Calculate next suitable version tag from git

You would like to automatically and programmatically find the next suitable version number for a release in Git.

#!/bin/bash

latest=$(git tag -l | sort -V | tail -n1)
semver_parts=(${latest//./ })
major=${semver_parts[0]}
minor=${semver_parts[1]}
patch=${semver_parts[2]}

patch_version=${major}.${minor}.$((patch+1))
minor_version=${major}.$((minor+1)).0
major_version=$((major+1)).0.0

echo "latest:        $latest"
echo "patch release: $patch_version"
echo "minor release: $minor_version"
echo "major release: $major_version"

Issue:

You would like to automatically and programmatically find the next suitable version number for a release in Git.

Prerequisites:

You are working by semantic versioning principles.

Solution:

Save and execute the provided snippet into your terminal.

13.11.2025 | Marc Hitscherich

Simple domain redirect in Kubernetes with nginx ingress

You want to establish a redirect from an old domain of a client to their new domain but the certificate should remain the same, supporting all URI arguments

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: old-domain-redirect
  namespace: my-namespace
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    nginx.ingress.kubernetes.io/permanent-redirect: https://new-domain.com$request_uri
    nginx.ingress.kubernetes.io/ssl-redirect: 'true'
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: old-domain.com
  tls:
  - hosts:
    - old-domain.com
    secretName: old-domain.com-cert

Issue:

You want to establish a redirect from an old domain of a client to their new domain but the certificate should remain the same, supporting all URI arguments

Prerequisites:

This only works for kubernetes / K8S and nginx ingress based infrastructure environments.

Solution:

Use the snippet provided.

13.11.2025 | Marc Hitscherich

List MySQL tables by size

You need to sort MySQL tables by size.

SELECT table_name AS `table`, round(((data_length + index_length) / 1024 / 1024), 2) `size in MB`
FROM information_schema.TABLES
WHERE table_schema = "DATABASE_NAME"
ORDER BY `size in MB` DESC
LIMIT 10;

Issue:

You need to sort MySQL tables by size.

Solution:

The snippet shows the size of the 10 biggest tables. DATABASE_NAME needs to be replaced by your database name.

13.11.2025 | Nikolas Kopp

Clear APC & Opcache

You need to clear APC and Opcache, e.g. for debugging purposes.

<?php

apcu_clear_cache();
opcache_reset();

Issue:

You need to clear APC and Opcache, e.g. for debugging purposes.

Solution:

drush php:script clear_cache 

This snippet clears APCu and Opcache. Put it into the docroot. Execute from browser, not from CLI.

See the drush documentation for more info.

13.11.2025 | Michael Ebert

Warm your Drupal caches after a cache clear

We all know the problem that a Drupal site may be loading slowly after a cache clear.

tags:
  - { name: cache_prewarmable }
/**
  * Implements \Drupal\Core\PreWarm\PreWarmableInterface.
  */
public function preWarm(): void {
  $this->getDefinitions();
}

Issue:

We all know the problem that a Drupal site may be loading slowly after a cache clear.

Prerequisites:

  • Drush ≥ 13.5
  • Drupal ≥ 11.2

Solution:

There is a new prewarm API introduced in Drupal 11.2. This allows you to add a `cache_prewarmable` tag to your services and implement a preWarm method. If you are using Drush version 13.5 or newer, it will automatically call a `cache:warm` as last step when doing a `drush deploy`.

This will only warm cache cache items that are used to build most pages, plugins and registries, but not render caching or anywhere like that. 

Furter informations can be found here: 

18.06.2024 | Dominik Wille

Prevent destination URLs from being indexed by search engines

Search engines might index URLs multiple times if they have different destination parameters. For example if you have a login form in the sidebar the action URL might be different on each page.

Disallow: /*?destination=
Disallow: /*&destination=

Issue:

Search engines might index URLs multiple times if they have different destination parameters. For example if you have a login form in the sidebar the action URL might be different on each page.

Solution:

Insert the provided entries into your robots.txt file.