Symfony Cache with Database

The Symfony Cache component has a large number of possible adapters for cached information.

For caching in the database, you can use the following PdoAdapter for Doctrine and configure the following dimensions:

                adapter: AppCache
  class: Symfony\Component\Cache\Adapter\PdoAdapter
    - '@doctrine.dbal.default_connection'

Symfony thus generates a database table within the default database connection for the cache entries.

This has particularly performance gains and is clearer compared to the default file system variant. This is especially recommended for a Docker environment, because the slow file system does not need to be diluted.

Symfony 5 Exception “The annotation was never imported.”

One reason for the error message may be, that it is actually an annotation, that is invalid, but is in the vendor code. Then you should ignore them.

Error message:

Doctrine\Common\Annotations\AnnotationException : [Semantical Error] The annotation "@suppress" in method Monolog\Formatter\LineFormatter::normalizeException() was never imported. Did you maybe forget to add a "use" statement for this annotation?

If you ignore the annotation with the static call to in the config/bootstrap.php:



Create your own metrics in AWS Cloudwatch

To use CloudWatch Create your own metrics, by e.g.. alarm and to operate monitoring with the data of the application, can you use the aws-php-sdk use the following code:

 $client = new CloudWatchClient([
        'region' => 'eu-central-1',
        'version' => '2010-08-01',
        'credentials' => [
            'key'    => 'xxx',
            'secret' => 'xxx
$result = $this->client->putMetricData(array(

    'Namespace' => 'MyProject',
    'MetricData' => array(
            'MetricName' => 'MyMetric,
            'Timestamp' => time(),
            'Value' => 1,
            'Unit' => 'Count',
            'Dimensions' => array(
                    'Name' => 'Environment',
                    'Value' => 'test',

DockerFile PHP with XDebug and Amazon Linux 2

A DockerFile for a PHP 7.2. Environment with XDebug for a Symfony 4 Environment on Amazon Linux 2:

FROM amazonlinux:2.0.20190823.1

RUN yum install -y

# install php
RUN amazon-linux-extras install -y php7.2
RUN yum install -y php-devel.x86_64 php-xml.x86_64 php-pecl-zip.x86_64  php-intl.x86_64

#install xdebug
RUN yum install -y gcc make
RUN yum install -y php-pear.noarch
RUN pecl install xdebug
RUN echo 'zend_extension=/usr/lib64/php/modules/' >> /etc/php.ini

CREATE PHP csv File with Umlauts for Excel

To create a csv file, where the umlauts are correctly coded, you have to be in your project, which is normally encoded UTF-8, encode the umlauts according to UTF-16LE. This encoding can be viewed from Windows and Mac.

$file = fopen('file.csv', 'w');
foreach ($rows as $row) {
 $row = array_map(function($cell){
 return mb_convert_encoding($cell, 'UTF-16LE', 'UTF-8');
 }, $row);
 fputcsv($file, $row, ';');

Configuring Monolog Logging for AWS Cloudwatch Logs

So that the logs are beautifully formatted from a Symfony 4 Arrive application in AWS Cloudwatch, must be Monologue configure as follows:

# config/services.yaml
        - [includeStacktraces]


# config/packages/prod/monolog.yaml
      type:  stream
      level: error
      path:  '%kernel.logs_dir%/error.log'
      formatter: Monolog\Formatter\JsonFormatter

After that, you have to Cloudwatch Daemon to configure:

# /etc/awslogs/awslogs.conf
# Path to the CloudWatch Logs agent's state file. The agent uses this file to maintain
# client side state across its executions.
state_file = /var/lib/awslogs/agent-state

datetime_format = [%Y-%m-%d H:%M:%S]
file = /var/www/html/var/log/error.log
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = test_group_name/error_log

and you get wonderful (Aggregated) ErrorLog Information in Cloudwatch Logs Insight:



Symfony Switftmailer Mail is not sent

With the following command a test mail can be sent with Swiftmailer. If the email does not arrive, the Switftmailer parameters are inconfig/packages/swiftmailer.yaml probably wrong:

php bin/console swiftmailer:email:send --help

Since the email is sent with a queue, should nevertheless be Error_log be examined under var/log/, in it found with me the reason for my shipping problem:

app.ERROR: Exception occurred while flushing email queue: Expected response code 250 but got code "554", with message "554 Message rejected: 
Email address is not verified. The following identities failed the check in region EU-WEST-1: email1, email2


Tutorial: Administration backend create symfony

In this post, I'm going with Symfony 4 an Administartionsoberfläche with the help of Sonata create and describe the steps.

1. Create a new symfony project

With composer can be quickly skeleton project creating a new symfony:

composer create-project symfony/website-skeleton my-admin-demo

The skeleton project contains the main symfony components for a Web application and doctrine.

Now is a good time to check in the Porjket in a Versionierungsystem like GIT and to commit for the first time.

Optionally, symfony PHPUnit bridge can now be installed, When tests should be written:

composer require phpunit --dev

The database can now be configured in the .env file:


And are created with the following command:

php bin/console doctrine:database:create

2. Installation of the SonataAdmin bundle more…