Ashraf Hassan Ashraf Hassan - 5 months ago 7
PHP Question

Postfixadmin is not working with Postgres

I am new to both postgres and postfix, I decided to use to postfixadmin with Postgres to gain so hands on, I have ran through detailed steps mentioned in different websites, and I have checked another working installation of Postgres (but without postfixadmin), but whenever I accessing the setup.php for postfixadmin from http://mydomain.com:8080 I am getting:

Error: Can't connect to database
Please edit the $CONF['database_*'] parameters in config.inc.php.
DEBUG INFORMATION:
Connect: failed to connect to database.


I configured the postfixadmin to use initially postfix user, but as the postfix is created by default as no login user, so I created another user called admin and changed this in config.inc.php as well, but I am still getting the same error

Here are the user created on the system related to this stuff:

# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
postgres:x:26:26:PostgreSQL Server:/var/lib/pgsql:/bin/bash
admin:x:500:500::/home/admin:/bin/bash


Here am I configuring the user admin in Postgres:

# su - postgres
-bash-4.1$ template1
-bash: template1: command not found
-bash-4.1$ template1#
-bash: template1#: command not found
-bash-4.1$ psql template1
psql (8.4.18)
Type "help" for help.
template1=# CREATE USER admin WITH PASSWORD 'complexpassword';
CREATE ROLE
template1=# GRANT ALL PRIVILEGES ON DATABASE postfix to admin;
GRANT
template1=# \q
-bash-4.1$ logout


Here are the configuration of the Postgres:

-bash-4.1$ psql
psql (8.4.18)
Type "help" for help.

postgres=# \list
List of databases
Name | Owner | Encoding | Collation | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postfix | postfix | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postfix
: postfix=CTc/postfix
: admin=CTc/postfix
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres
: postgres=CTc/postgres
(4 rows)


Here is postgresql.conf:

#cat postgresql.conf
listen_addresses = 'localhost' # what IP address(es) to listen on;
port = 5432 # (change requires restart)
max_connections = 100 # (change requires restart)
shared_buffers = 32MB # min 128kB
synchronous_commit = off # optimization
log_destination = 'stderr' # Valid values are combinations of
logging_collector = on # Enable capturing of stderr and csvlog
log_directory = 'pg_log' # directory where log files are written,
log_filename = 'postgresql-%a.log' # log file name pattern,
log_truncate_on_rotation = on # If on, an existing log file of the
log_rotation_age = 1d # Automatic rotation of logfiles will
log_rotation_size = 0 # Automatic rotation of logfiles will
datestyle = 'iso, mdy'
lc_messages = 'en_US.UTF-8' # locale for system error message
lc_monetary = 'en_US.UTF-8' # locale for monetary formatting
lc_numeric = 'en_US.UTF-8' # locale for number formatting
lc_time = 'en_US.UTF-8' # locale for time formatting
default_text_search_config = 'pg_catalog.english'


Here I am testing user admin:

# su - admin
$ psql -d postfix -U admin
psql (8.4.18)
Type "help" for help.
postfix=> exit
postfix-> \q


Here I am testing postfix user (nologin):

# su - postfix
This account is currently not available.


Here is the config.inc.php for postfixadmin:

<?php
$CONF['configured'] = true;
$CONF['setup_password'] = 'complexpassword';
$CONF['postfix_admin_path'] = dirname(__FILE__);
$CONF['default_language'] = 'en';
$CONF['database_type'] = 'pgsql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'admin';
$CONF['database_password'] = 'complexpassword';
$CONF['database_name'] = 'postfix';
$CONF['database_port'] = '5432';
$CONF['database_prefix'] = '';
$CONF['database_tables'] = array (
'admin' => 'admin',
'alias' => 'alias',
'alias_domain' => 'alias_domain',
'config' => 'config',
'domain' => 'domain',
'domain_admins' => 'domain_admins',
'fetchmail' => 'fetchmail',
'log' => 'log',
'mailbox' => 'mailbox',
'vacation' => 'vacation',
'vacation_notification' => 'vacation_notification',
'quota' => 'quota',
'quota2' => 'quota2',
);
$CONF['admin_email'] = 'postmaster@mydomain.com';
$CONF['smtp_server'] = 'localhost';
$CONF['smtp_port'] = '25';
$CONF['encrypt'] = 'md5crypt';
$CONF['authlib_default_flavor'] = 'md5raw';
$CONF['min_password_length'] = 5;
$CONF['generate_password'] = 'NO';
$CONF['show_password'] = 'NO';
$CONF['page_size'] = '10';
$CONF['default_aliases'] = array (
'abuse' => 'abuse@mydomain.com',
'hostmaster' => 'hostmaster@mydomain.com',
'postmaster' => 'postmaster@mydomain.com',
'webmaster' => 'webmaster@mydomain.com'
);
$CONF['domain_path'] = 'NO';
$CONF['domain_in_mailbox'] = 'YES';
$CONF['maildir_name_hook'] = 'NO';
maildir_name_hook example function
Called by create-mailbox.php if $CONF['maildir_name_hook'] == '<name_of_the_function>'
- allows for customized maildir paths determined by a custom function
- the example below will prepend a single-character directory to the
beginning of the maildir, splitting domains more or less evenly over
36 directories for improved filesystem performance with large numbers
of domains.
Returns: maildir path
function maildir_name_hook($domain, $user) {
$chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$dir_index = hexdec(substr(md5($domain), 28)) % strlen($chars);
$dir = substr($chars, $dir_index, 1);
}
$CONF['aliases'] = '10';
$CONF['mailboxes'] = '10';
$CONF['maxquota'] = '10';
$CONF['quota'] = 'NO';
$CONF['quota_multiplier'] = '1024000';
$CONF['transport'] = 'NO';
$CONF['transport_options'] = array (
);
$CONF['transport_default'] = 'virtual';
$CONF['vacation'] = 'NO';
$CONF['vacation_domain'] = 'autoreply.hassans.nl';
$CONF['vacation_control'] ='YES';
$CONF['vacation_control_admin'] = 'YES';
$CONF['alias_control'] = 'NO';
$CONF['alias_control_admin'] = 'NO';
$CONF['special_alias_control'] = 'NO';
$CONF['alias_goto_limit'] = '0';
$CONF['alias_domain'] = 'YES';
$CONF['backup'] = 'YES';
$CONF['sendmail'] = 'YES';
$CONF['logging'] = 'YES';
$CONF['fetchmail'] = 'YES';
$CONF['fetchmail_extra_options'] = 'NO';
$CONF['show_header_text'] = 'NO';
$CONF['header_text'] = ':: Postfix Admin ::';
$CONF['show_footer_text'] = 'YES';
$CONF['footer_text'] = 'Return to mail.mydomain.com';
$CONF['welcome_text'] = <<<EOM
Hi,
Welcome to your new account.
EOM;
$CONF['emailcheck_resolve_domain']='YES';
$CONF['show_status']='NO';
$CONF['show_status_key']='NO';
$CONF['show_status_text']='&nbsp;&nbsp;';
$CONF['show_undeliverable']='NO';
$CONF['show_undeliverable_color']='tomato';
$CONF['show_undeliverable_exceptions']=array("unixmail.domain.ext","exchangeserver.domain.ext","gmail.com");
$CONF['show_popimap']='NO';
$CONF['show_popimap_color']='darkgrey';
$CONF['show_custom_domains']=array("subdomain.domain.ext","domain2.ext");
$CONF['show_custom_colors']=array("lightgreen","lightblue");
$CONF['recipient_delimiter'] = "";
$CONF['create_mailbox_subdirs_prefix']='INBOX.';
$CONF['used_quotas'] = 'NO';
$CONF['new_quota_table'] = 'NO';
$CONF['xmlrpc_enabled'] = false;
}


Here are the php packages installed:

#rpm -qa| grep php
php-common-5.3.3-26.el6.x86_64
php-pgsql-5.3.3-26.el6.x86_64
php-xmlrpc-5.3.3-26.el6.x86_64
php-cli-5.3.3-26.el6.x86_64
php-5.3.3-26.el6.x86_64
php-gd-5.3.3-26.el6.x86_64
php-pear-1.9.4-4.el6.noarch
php-imap-5.3.3-26.el6.x86_64
php-xml-5.3.3-26.el6.x86_64
php-pdo-5.3.3-26.el6.x86_64
php-mbstring-5.3.3-26.el6.x86_64


Here are the checks showing that the Postgres is listening to posrt 5432:

#netstat -an|grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
unix 2 [ ACC ] STREAM LISTENING 12136 /tmp/.s.PGSQL.5432


# telnet localhost 5432
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
^]
telnet> quit
Connection closed.


But What is really strange as well when I try to run the setup.php page I can see the following:

# netstat -an| grep 5432
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:45445 127.0.0.1:5432 TIME_WAIT
unix 2 [ ACC ] STREAM LISTENING 12136 /tmp/.s.PGSQL.5432


The Postgres' log contains:

LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "postfix"
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "postfix"
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused
FATAL: Ident authentication failed for user "postfix"
LOG: could not connect to Ident server at address "127.0.0.1", port 113: Connection refused FATAL:
Ident authentication failed for user "admin"


And the
pg_hba.conf
is:

local all all ident
host all all 127.0.0.1/32 ident
host all all ::1/128 ident


Can someone guide me what is wrong?

Answer

Find in the pg_hba.conf(this file is in the same directory as the postgresql.conf) a line starting with "host", containing "127.0.0.1/32" in it and ending with "ident" and change the "ident" to "md5". Reload/restart Postgres.