Installing and configuring PostfixAdmin

Please note that this information is no longer up to date. The content of this site has moved to a new domain DIYMacServer.com which is kept up to date. Apologies for the inconvienince.

What to do to install the Postfix Admin package on our server and what to do to solve the bugs we’ve encountered.

First you need to download the software package from the Postfix Admin site, I’m using and basing these instructions on version 2.1.0. Don’t use the installation guide that comes with the installation package as some of the steps you have already performed and might conflict with other parts of the installation.

Extract the package into the directory /Library/Apache2/htdocs, that is if you used these installation instructions. Otherwise extract it in the document root of your Apache installation.

For ease of use you can rename the directory postfixadmin-2.1.0 to just postfixadmin or create a symbolic link to that directory as follows:

sudo ln -s /Library/Apache2/htdocs/postfixadmin-2.1.0 \
        /Library/Apache2/htdocs/postfixadmin

Because you will enter the database user and password in the configuration files located in this directory it will be a lot safer if you change ownership and the permissions.

chown -R www:www /Library/Apache2/htdocs/postfixadmin-2.1.0

cd /Library/Apache2/htdocs/postfixadmin-2.1.0
chmod 640 *.php *.css
cd /Library/Apache2/htdocs/postfixadmin-2.1.0/admin/
chmod 640 *.php .ht*
cd /Library/Apache2/htdocs/postfixadmin-2.1.0/images/
chmod 640 *.gif *.png
cd /Library/Apache2/htdocs/postfixadmin-2.1.0/languages/
chmod 640 *.lang
cd /Library/Apache2/htdocs/postfixadmin-2.1.0/templates/
chmod 640 *.tpl
cd /Library/Apache2/htdocs/postfixadmin-2.1.0/users/
chmod 640 *.php

When you’ve done this you are ready to create the configuration file. Copy the file config.inc.php.sample in the directory /Library/Apache2/htdocs/postfixadmin to config.inc.php to get a starting point. Then edit the file config.inc.php and change following items:

// the location of the files:
$CONF['postfix_admin_url'] = '/postfixadmin/admin';
$CONF['postfix_admin_path'] =
     '/Library/Apache2/htdocs/postfixadmin/admin';

// how to connect to the database
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['database_prefix'] = '';

// your administrator e-mail address
$CONF['admin_email'] = 'postmaster@yourmaindomain.tld';

// The default aliases that need to be created for all domains.
$CONF['default_aliases'] = array (
        'abuse' => 'abuse@yourmaindomain.tld',
        'hostmaster' => 'hostmaster@yourmaindomain.tld',
        'postmaster' => 'postmaster@yourmaindomain.tld',
        'webmaster' => 'webmaster@yourmaindomain.tld'
);

// to get a mailbox structure like /domain/user
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';

Next, to secure the overall admin module you need to edit the file .htaccess in the directory /Library/Apache2/htdocs/postfixadmin/admin. Change the line

AuthUserFile /usr/local/www/<domain.tld>/admin/.htpasswd

into this:

AuthUserFile /Library/Apache2/htdocs/postfixadmin/admin/.htpasswd

You need to do the final step by starting up your favourite browser and point it to http://localhost/postfixadmin/. Click on the setup link for the final step, it will do a test and checkup. After you got it working remove the setup.php file from the directory /Library/Apache2/htdocs/postfixadmin or rename it to keep your server safe.

You can then go into http://localhost/postfixadmin/admin/ to administrate your users and domain admins. Please note that the default user and password for this is admin/admin and that that is defined in the .htpasswd file in the directory /Library/Apache2/htdocs/postfixadmin/admin. To change the default password you can go into the directory /Library/Apache2/htdocs/postfixadmin/admin as root and type the following command:

htpasswd -c .htpasswd admin

You then will be asked to type the new password twice, if you did that correctly the password has changed.

NOTE:
There is an old bug in the sendmail function that send improper SMTP commands for our setup. You need to edit the file functions.inc.php in the postfixadmin directory. Find the function smtp_mail() and change the line:

fputs ($fh, "EHLO $smtp_server\r\n");

into:

fputs ($fh, "HELO $smtp_server\r\n");

16 Responses to “Installing and configuring PostfixAdmin”

  1. K. Nijmeijer Says:

    Hey Richard5,

    Thanks for this Great Guide!
    But I encountered a problem, when accessing localhost/postfixadmin/index.php I get this error message:

    Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0

    Warning: Unknown: Failed opening ‘/Library/Apache2/htdocs/postfixadmin/index.php’ for inclusion (include_path=’.:/Library/PHP5/lib/php’) in Unknown on line 0

    I also noticed that accessing localhost/postfixadmin results in a directory listing, not in loading the index.php.

    Got the feeling I’m overseeing something rather simple.
    Any suggestions?

    Richard5: Problem was that Apache was not running as the www user.

  2. Dave Says:

    I have the same problem, described above.
    I installed everything according to your tutorial.

    How may i check/change the user apache is running at?

  3. Richard5 Says:

    ps -aux | grep httpd

    Shows as which user Apache is running. To change the user find the options in your httpd.conf:
    User www
    Group www

  4. Dave Says:

    Thanks. That helped.
    One of my last remaining problems is now, that apache seems to ignore the .htaccess … it just lets me in – without prompting for a password.

  5. Richard5 Says:

    I guess you missed an AllowOverride setting somewhere in you httpd.conf. You must be enabled to allow the use of .htaccess.

    Set it from None, to All or AuthConfig, read the manual on httpd for more info.

  6. Stephen Says:

    With all the default settings….I get this.

    I have set a root password on the database, but nothing else
    I copied the default php.ini file to /etc as php.ini
    The web server is running as www (not daemon)

    DEBUG INFORMATION:
    Connect: Access denied for user ‘postfixadmin’@'localhost’ (using password: YES)

    Please check the documentation and website for more information.

    Postfix Admin
    Knowledge Base

  7. Stephen Says:

    change to root user, I get

    DEBUG INFORMATION:
    MySQL Select Database: Unknown database ‘postfix’

    Please check the documentation and website for more information.

    Postfix Admin
    Knowledge Base

  8. Richard5 Says:

    Did you install any of the previous stuff of the mailserver setup ? The database should be there ?

  9. James Brown Says:

    cd /Library/Apache2/htdocs/postfixadmin-2.1.0/images/
    sudo chmod 640 *.gif *.png
    chmod: *.gif: No such file or directory

    As there are no gifs in this directory, should get rid of *.gif in the chmod command?

  10. Tom Moore Says:

    Check out Postfix Enabler and MailServe from Bernard Teo. No noodling around with the terminal needed!

  11. Richard5 Says:

    Sorry Tom, but I disagree, it’s not the same. Bernard’s solution is a very good solution for simple mail-server needs which might be enough for you. My solution gives you full virtual mail users which don’t need to have an user account on your Mac.

  12. michael Says:

    when trying to access the posftixadmin/admin URL I get the error:

    DEBUG INFORMATION:
    Connect: Client does not support authentication protocol requested by server; consider upgrading MySQL client.

    Could this be due to the fact that I didn’t install any of the SSL parts of the tutorial?

  13. Dennis Says:

    When I login as postfixadmin/admin I go to a list of .php files. If I select one I get

    DEBUG INFORMATION:
    Connect: Access denied for user ‘postfixadmin’@'localhost’ (using password: YES)

    I think there may be multiple places where a password is stored. I know I’m using the one I set but something is wrong.

  14. Igors Says:

    Hi, Richard
    I have same problem with blank list-admin.php. The www user is www-data, so I’ve chmod’ed and chown’ed recursevly postfixadmin to www-data:www-data.

    I can pass setup, but after redirecting to /postfixadmin/admin/list-admin.php the page keeps blank.

    Any ideas on this issue?
    Thanks!

  15. Moayad Says:

    hi,
    there’s a newer version of postfix.admin including rename accounts and mail forwarding features?

    Thanks

  16. dShadow Says:

    THANK’S A LOT!!!

    chown -R apache:apache /var/www/html/padmin

    and now it is working!!!
    They should to write it in the install.txt