DB Socket connection

Your software
My Mautic version is: 5.0.3
My PHP version is: 8.1
My Database type and version is: mariadb 10.11.6

Your problem
My problem is: Initial DB connection setup

I’m attempting to install mautic for the first time. I’m using the .zip method.

I can get to the onboarding screen but am unable to connect to my database.

I am trying to use a unix socket connection (I have to connect this way TCP connection won’t work with my topology).

Is there a specific format that the connection needs to be specified with? I have tried “localhost:/tmp/mariadb/mysql.sock” and similar variations but get the error;

An error occured while attempting to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] Address not available

I have not tried this, but I think you will need to override the config a bit.

Here is what I have found, maybe it can steer you in the right direction.

Here is the app/config/config.php:

you need to override the connection settings in such a way that you add unix_socket option to the array with the path to your socket. So something like:

// 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',
    'unix_socket' => '/path/to/your/mysql.sock',
    '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',

$container->loadFromExtension('doctrine', [
    'dbal' => [
        'default_connection' => 'default',
        'connections'        => [
            'default'    => $connectionSettings,
            'unbuffered' => array_merge($connectionSettings, [
                'options' => [
                    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false,
                    \PDO::ATTR_STRINGIFY_FETCHES       => true, // @see https://www.php.net/manual/en/migration81.incompatible.php#migration81.incompatible.pdo.mysql
        'types'    => [
            'array'     => \Mautic\CoreBundle\Doctrine\Type\ArrayType::class,
            'datetime'  => \Mautic\CoreBundle\Doctrine\Type\UTCDateTimeType::class,
            'generated' => \Mautic\CoreBundle\Doctrine\Type\GeneratedType::class,
    'orm'  => [
        'auto_generate_proxy_classes' => '%kernel.debug%',
        'auto_mapping'                => true,
        'mappings'                    => $bundleMetadataBuilder->getOrmConfig(),
        'dql'                         => [
            'string_functions' => [
                'match' => \DoctrineExtensions\Query\Mysql\MatchAgainst::class,

Thanks for the response, adding 'unix_socket' => '/run/mysqld/mysql.sock', doesn’t seem to help, are there any other edits I missed?

I’m currently fighting a recursive 301 redirect issue too but think I have that one figured out.

A brief summary of where I am with this;

I initially attempted to set this up by extracting the zip file to the root of an nginx server and had the issue that I can’t connect to the DB via a unix socket. I reconfigured things so I could connect via TCP and once the installation was complete I couldn’t access the dashboard, it was instructing the browser to download a file called “dashboard” which contained php code.

Next I decided the better option would be to just run the official mautic/apache docker container. I have that up and running (after fighting with 301 redirect issues) using the bridge docker network. It can connect to my mariadb container on the same host.

For security reasons I usually run containers in a locked down network environment that doesn’t have access to other containers, hence my need to connect via unix socket. If I move this container to it’s own network (so it can’t connect to mariadb via TCP) it breaks (as expected). I have the mariadb unix socket passed into the mautic container at /run/mysqld/mysql.sock (this works with all the other containers I have set up that need DB access) but getting mautic to use it instead of connecting via TCP is being problematic.

If it helps this is my docker run command (that works when connecting to mariadb via TCP).

docker run
-e ‘MAUTIC_DB_DATABASE’=‘mautic’
-e ‘MAUTIC_DB_USER’=‘mautic’
-e ‘MAUTIC_DB_PASSWORD’=‘redacted’
-e ‘MAUTIC_DB_PORT’=‘3306’
-p ‘8098:80/tcp’
-v ‘/mnt/cache/appdata/mariadb/db_sock/’:‘/run/mysqld/’:‘rw’
-v ‘/mnt/cache/appdata/mautic/config/’:‘/var/www/html/config’:‘rw’
-v ‘/mnt/cache/appdata/mautic/var/logs/’:‘/var/www/html/var/logs’:‘rw’
-v ‘/mnt/cache/appdata/mautic/media/files/’:‘/var/www/html/docroot/media/files’:‘rw’
-v ‘/mnt/cache/appdata/mautic/media/images/’:‘/var/www/html/docroot/media/images’:‘rw’
-v ‘/mnt/cache/appdata/mautic/cron/’:‘/opt/mautic/cron’:‘rw’
-v ‘/mnt/cache/appdata/mautic/config.php’:‘/var/www/html/docroot/app/config/config.php’:‘rw’
-v ‘/mnt/cache/appdata/mautic/index.php’:‘/var/www/html/docroot/index.php’:‘rw’ ‘mautic/mautic:5-apache’

I have some config files mounted externally so they will survive a container update and the container has access to the mariadb socket at /run/mysqld/mysql.sock.

What I need to do is to get mautic to use this socket instead so I can isolate the container from the local network.