0

I am trying to make my own mail service using Postfix, but I run into an issue in the setup phase, and it's that postfix can't connect to the database. Here's what the error log says:

⛔Database connection string : mysql:host=localhost;dbname=postfixadmindb;charset=UTF8
⛔Problem connecting to database, check database configuration ($CONF['database_*'] entries in config.local.php)
⛔SQLSTATE[HY000] [2002] Permission denied

Here's the config file:

<?php
        $CONF['database_type'] = 'mysqli';
        $CONF['database_host'] = 'localhost';
        $CONF['database_user'] = 'postfixuser';
        $CONF['database_password'] = 'XXXXXXXX';
        $CONF['database_name'] = 'postfixadmindb';
        $CONF['configured'] = true;
        $CONF['encrypt'] = 'md5crypt';
        $CONF['setup_password'] = 'the setup password';
?>

First of all, I tried connecting to the database normally:
sudo mysql -u postfixuser -p'thecorrectpassword' -h localhost postfixadmindb
This works fine and brings me tho the MariaDB shell as expected
I then granted postfixuser all privileges in the database, but that didn't solve the issue.
I checked the log under /var/log/mysql/error.log but it's empty

I'm doing this on a WSL machine running Ubuntu 22.04.1 LTS, serving the postfixadmin web pages with apache.

1 Answers1

0

Running sudo mysql -u postf.. will run the mysql command-line client with root privileges and is an insufficient check to see if an unprivileged user can also connect to the mysql socket.

Try running that again without sudo and if that fails with an error such as Can't connect to local server through socket '/run/mysqld/mysqld.sock'there may be a file system permission problem that prevents the postfix user from connecting to the database via the MariaDB socket.

Changing the file system permissions on that directory/path is then the solution.

sudo chmod 0755  /run/mysqld/

It should be noted that directories under /run and/or /var/run are often created at boot time by systemd, in this case by the MySQL/MariaDB service unit.

You may need to edit the systemd unit file to make that change in permissions persistent.
If the RuntimeDirectory directive is used you would need to set the correct permissions with the RuntimeDirectoryMode=0755 directive.

If tempfiles.d is used, edit the spec for that

HBruijn
  • 84,206
  • 24
  • 145
  • 224