mautic/docker-mautic

Worker not working on fpm-nginx v5

mchojrin opened this issue ยท 14 comments

Hi:

I just cloned the repo and run docker-compose -f examples/fpm-nginx/docker-compose.yml up and I get this error:

fpm-nginx-mautic_worker-1  | 2024-02-06 09:58:46,298 INFO spawned: 'messenger-consume-failed_01' with pid 3068
fpm-nginx-mautic_worker-1  | In ConnectionFactory.php line 183:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred while establishing a connection to figure out your pl  
fpm-nginx-mautic_worker-1  |   atform version.                                                              
fpm-nginx-mautic_worker-1  |   You can circumvent this by setting a 'server_version' configuration value    
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   For further information have a look at:                                      
fpm-nginx-mautic_worker-1  |   https://github.com/doctrine/DoctrineBundle/issues/673                        
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ExceptionConverter.php line 101:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or  
fpm-nginx-mautic_worker-1  |    directory                                                                   
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Exception.php line 28:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Driver.php line 34:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ConnectionFactory.php line 183:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred while establishing a connection to figure out your pl  
fpm-nginx-mautic_worker-1  |   atform version.                                                              
fpm-nginx-mautic_worker-1  |   You can circumvent this by setting a 'server_version' configuration value    
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   For further information have a look at:                                      
fpm-nginx-mautic_worker-1  |   https://github.com/doctrine/DoctrineBundle/issues/673                        
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ExceptionConverter.php line 101:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or  
fpm-nginx-mautic_worker-1  |    directory                                                                   
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Exception.php line 28:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Driver.php line 34:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ConnectionFactory.php line 183:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred while establishing a connection to figure out your pl  
fpm-nginx-mautic_worker-1  |   atform version.                                                              
fpm-nginx-mautic_worker-1  |   You can circumvent this by setting a 'server_version' configuration value    
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   For further information have a look at:                                      
fpm-nginx-mautic_worker-1  |   https://github.com/doctrine/DoctrineBundle/issues/673                        
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ExceptionConverter.php line 101:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or  
fpm-nginx-mautic_worker-1  |    directory                                                                   
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Exception.php line 28:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Driver.php line 34:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ConnectionFactory.php line 183:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred while establishing a connection to figure out your pl  
fpm-nginx-mautic_worker-1  |   atform version.                                                              
fpm-nginx-mautic_worker-1  |   You can circumvent this by setting a 'server_version' configuration value    
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   For further information have a look at:                                      
fpm-nginx-mautic_worker-1  |   https://github.com/doctrine/DoctrineBundle/issues/673                        
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ExceptionConverter.php line 101:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or  
fpm-nginx-mautic_worker-1  |    directory                                                                   
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Exception.php line 28:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Driver.php line 34:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ConnectionFactory.php line 183:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred while establishing a connection to figure out your pl  
fpm-nginx-mautic_worker-1  |   atform version.                                                              
fpm-nginx-mautic_worker-1  |   You can circumvent this by setting a 'server_version' configuration value    
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   For further information have a look at:                                      
fpm-nginx-mautic_worker-1  |   https://github.com/doctrine/DoctrineBundle/issues/673                        
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ExceptionConverter.php line 101:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or  
fpm-nginx-mautic_worker-1  |    directory                                                                   
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Exception.php line 28:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Driver.php line 34:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ConnectionFactory.php line 183:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred while establishing a connection to figure out your pl  
fpm-nginx-mautic_worker-1  |   atform version.                                                              
fpm-nginx-mautic_worker-1  |   You can circumvent this by setting a 'server_version' configuration value    
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   For further information have a look at:                                      
fpm-nginx-mautic_worker-1  |   https://github.com/doctrine/DoctrineBundle/issues/673                        
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In ExceptionConverter.php line 101:
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  |   An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or  
fpm-nginx-mautic_worker-1  |    directory                                                                   
fpm-nginx-mautic_worker-1  |                                                                                
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Exception.php line 28:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory  
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  | 
fpm-nginx-mautic_worker-1  | In Driver.php line 34:
fpm-nginx-mautic_worker-1  |                                                     
fpm-nginx-mautic_worker-1  |   SQLSTATE[HY000] [2002] No such file or directory

The site seems to work fine. I'm trying this out locally before upgrading my server from 4 to 5. Thanks

Same happens with basic example

Looking at the file app/config/config.php inside the docroot directory of the worker container I see this line:

'server_version' => '%env(mauticconst:MAUTIC_DB_SERVER_VERSION)%',

So I guess this value should be set in the .mautic_env file to "8.0.36", the current MySQL version found in the container...

Just tried that, rebuilt the containers and still getting the same error :(

More info: I looked for definitions of the constant MAUTIC_DB_SERVER_VERSION and found the file app/AppKernel.php.

Inside it there's this snippet, taken from the class constructor:

      /**
         * This is required for Doctrine's automatic database detection. When Mautic hasn't been
         * installed yet, we don't have a database to connect to, causing automatic database platform
         * detection to fail. We use the MAUTIC_DB_SERVER_VERSION constant to temporarily set a server_version
         * if no database settings have been provided yet.
         */
        if (!defined('MAUTIC_DB_SERVER_VERSION')) {
            $localConfigFile = ParameterLoader::getLocalConfigFile($this->getApplicationDir().'/app', false);
            define('MAUTIC_DB_SERVER_VERSION', file_exists($localConfigFile) ? null : '5.7');
        }

Following the indication on the comment, I figured once the app was installed the problem would go away but that's not the case.

@mchojrin thanks for the report.

I think it's related on how the db connection details are stored in your config.php file.
does it look like this?

<?php
$parameters = array(
	'db_driver' => 'pdo_mysql',
	'db_host' => getenv('MAUTIC_DB_HOST'),
	'db_port' => getenv('MAUTIC_DB_PORT'),
	'db_name' => getenv('MAUTIC_DB_DATABASE'),
	'db_user' => getenv('MAUTIC_DB_USER'),
	'db_password' => getenv('MAUTIC_DB_PASSWORD'),

or like this?

<?php
$parameters = array(
	'db_driver' => 'pdo_mysql',
	'db_host' => 'db',
	'db_port' => '3306',
	'db_name' => 'mautic_db',
	'db_user' => 'mautic_db_user',
	'db_password' => 'mautic_db_pwd',

Hey @mollux , thanks for your reply. I'm affraid I don't have any of those options in my config.php file (It is app/config/config.php we're talking about, right?).

What I see that looks somewhat similar is this:

// Doctrine Configuration
$connectionSettings = [
    'driver'                => '%mautic.db_driver%',
    'host'                  => '%mautic.db_host%',
    'port'                  => '%mautic.db_port%',
    'dbname'                => '%mautic.db_name%',
    'user'                  => '%mautic.db_user%',
    'password'              => '%mautic.db_password%',
    'charset'               => 'utf8mb4',
    'default_table_options' => [
        'charset'    => 'utf8mb4',
        'collate'    => 'utf8mb4_unicode_ci',
        'row_format' => 'DYNAMIC',
    ],
    // Prevent Doctrine from crapping out with "unsupported type" errors due to it examining all tables in the database and not just Mautic's
    'mapping_types' => [
        'enum'  => 'string',
        'point' => 'string',
        'bit'   => 'string',
    ],
    'server_version' => '%env(mauticconst:MAUTIC_DB_SERVER_VERSION)%',
    'wrapper_class'  => \Mautic\CoreBundle\Doctrine\Connection\ConnectionWrapper::class,
    'options'        => [\PDO::ATTR_STRINGIFY_FETCHES => true], // @see https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql
];

if (!empty($localConfigParameterBag->get('db_host_ro'))) {
    $connectionSettings['wrapper_class']   = \Mautic\CoreBundle\Doctrine\Connection\PrimaryReadReplicaConnectionWrapper::class;
    $connectionSettings['keep_replica']    = true;
    $connectionSettings['replicas']        = [
        'replica1' => [
            'host'                  => '%mautic.db_host_ro%',
            'port'                  => '%mautic.db_port%',
            'dbname'                => '%mautic.db_name%',
            'user'                  => '%mautic.db_user%',
            'password'              => '%mautic.db_password%',
            'charset'               => 'utf8mb4',
        ],
    ];
}```

@mchojrin no I'm talking about /config/local.php, not /docroot/app/config/config.php

Can you check /config/local.php? If you're using the default examples, that config file is volume mapped to a local folder.

@mollux got it. The contents of the file are:

<?php
$parameters = array(
	'db_driver' => 'pdo_mysql',
	'db_host' => 'db',
	'db_port' => '3306',
	'db_name' => 'mautic_db',
	'db_user' => 'mautic_db_user',
	'db_password' => 'mautic_db_pwd',
	'db_table_prefix' => null,
	'db_backup_tables' => 1,
	'db_backup_prefix' => 'bak_',
	'secret_key' => '3f6b05a1a0e9c7ced2d4f079a1e9d5ce121be32d4b7841c35e1cc219aab004e8',
	'site_url' => 'http://localhost:8001',
);

facing same issue, any solution or workaround?

Same issue

@mchojrin @audacioustux @thisismzm

This is most likely related to missing env vars.
Can you try the changes in PR #263?

That should solve the issue

@mchojrin @audacioustux @thisismzm

This is most likely related to missing env vars. Can you try the changes in PR #263?

That should solve the issue

Yes, it solved the problem, thanks!

This seems to be working. Thanks!

thanks for the feedback, I'll merge the referenced PR