# DB Socket connection

**URL:** https://forum.mautic.org/t/db-socket-connection/31041
**Category:** Mautic 5 Install/Upgrade Support
**Created:** [February 24, 2024, 12:28am UTC](https://forum.mautic.org/t/db-socket-connection/31041 "2024-02-24T00:28:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![loki](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@loki](https://forum.mautic.org/u/loki)
#### Post date: [February 24, 2024, 12:28am UTC](https://forum.mautic.org/t/db-socket-connection/31041/1 "2024-02-24T00:28:26Z")

</div>

**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

---

<div class="post-metadata">

### Author: ![loki](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@loki](https://forum.mautic.org/u/loki)
#### Post date: [February 24, 2024, 12:29am UTC](https://forum.mautic.org/t/db-socket-connection/31041/2 "2024-02-24T00:29:21Z")

</div>

![mauticerror](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/6/6313788c4579ab1b9ffc51e305fcab41e3120545.png)

---

<div class="post-metadata">

### Author: ![mzagmajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mzagmajster/32/687_2.png) [@mzagmajster](https://forum.mautic.org/u/mzagmajster)
#### Post date: [February 24, 2024, 8:27am UTC](https://forum.mautic.org/t/db-socket-connection/31041/3 "2024-02-24T08:27:42Z")

</div>

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:

> <https://github.com/mautic/mautic/blob/e0ffc1c7132b44325793fd590c4a098f750c6cc8/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:

```auto
// 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,
            ],
        ],
    ],
]);

```

---

<div class="post-metadata">

### Author: ![loki](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@loki](https://forum.mautic.org/u/loki)
#### Post date: [February 24, 2024, 4:22pm UTC](https://forum.mautic.org/t/db-socket-connection/31041/4 "2024-02-24T16:22:17Z")

</div>

> [@mzagmajster](#):
>
> ```auto
> 'unix_socket' => '/path/to/your/mysql.sock',
> 
> ```

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.

---

<div class="post-metadata">

### Author: ![loki](https://avatars.discourse-cdn.com/v4/letter/l/3be4f8/32.png) [@loki](https://forum.mautic.org/u/loki)
#### Post date: [February 24, 2024, 4:37pm UTC](https://forum.mautic.org/t/db-socket-connection/31041/5 "2024-02-24T16:37:23Z")

</div>

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

> docker run  
> -d  
> –name=‘Mautic’  
> –net=‘bridge’  
> -e ‘MAUTIC\_DB\_DATABASE’=‘mautic’  
> -e ‘MAUTIC\_DB\_USER’=‘mautic’  
> -e ‘MAUTIC\_DB\_PASSWORD’=‘redacted’  
> -e ‘MAUTIC\_DB\_HOST’=‘192.168.10.10’  
> -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.
