How to Install Postfix on CentOS 6

Postfix Pre-Installation Steps

The first step before installing Postfix is to make sure that Sendmail is not already running on your system. You can check for this using the following command:

/sbin/service sendmail status

If sendmail is not installed, the tool will display a message similar to the following:

sendmail: unrecognized service

If sendmail is installed, but not running the following output will be displayed:

sendmail is stopped

If sendmail is running you will see the following:

sendmail (pid 2138) is running

If sendmail is running on your system it is necessary to stop it before installing and configuring Postfix. To stop sendmail run the following command as super user:

/sbin/service sendmail stop

The next step is to ensure that sendmail does not get restarted automatically when the system is rebooted. The first step is to find out which run levels will automatically start sendmail. To do this we can use the chkconfig command-line tool as follows:

/sbin/chkconfig --list | grep sendmail

The above command will typically result in output similar to:

sendmail     0:off   1:off   2:on   3:on   4:on    5:on   6:off

This means that if the system boots into runlevels 2, 3, 4 or 5 then the sendmail service will automatically start. To turn off sendmail we can once again use the chkconfig command as follows:

/sbin/chkconfig sendmail off

The chkconfig tool defaults to changing the settings for runlevels 2, 3, 4 and 5. You can configure for specific runlevels using the –levels command line option if necessary.

To verify the settings run chkconfig one more time as follows:

/sbin/chkconfig --list | grep sendmail

And check that the output is as follows:

sendmail  0:off  1:off   2:off   3:off  4:off   5:off   6:off

Sendmail is now switched off and configured so that it does not auto start when the system is booted. We can now move on to installing Postfix.

Installing Postfix on CentOS 6

By default, the CentOS 6 installation process installs Postfix for most configurations. To verify if Postfix is already installed, use the following rpm command in a Terminal window:

 
rpm -q postfix

If rpm reports that postfix is not installed, it may be installed as follows:

su -
yum install postfix

The yum tool will download and install postfix, and configure a special postfix user in the /etc/passwd file.

Configuring Postfix

The main configuration settings for Postfix are located in the /etc/postfix/main.cf file. There are many resources on the internet that provide detailed information on Postfix so this section will focus on the basic options required to get email up and running.

The key options in the main.cf file are:

myhostname = mta1.domain.com
mydomain = domain.com
myorigin = $myhostname
inet_interfaces = $myhostname

Other settings will have either been set up for you by the installation process or are not needed unless you are feeling adventurous and want to configure a more sophisticated email system.

The format of myhostname is host.domain.extension. For example if your Linux system is called MyLinuxHost and your internet domain is MyDomain.com you would set the myhostname option as:

myhostname = mylinuxhost.mydomain.com
The mydomain setting is just the domain part of the above setting. For example: 
mydomain = mydomain.com

The myorigin and inet_interfaces options use the settings we have just created so do not need to be changed (although the inet_interfaces may be commented out by default so you should remove the # at the beginning of this particular line in the main.cf file).

Starting Postfix on a CentOS 6 System

Once the /etc/postfix/main.cf file is configured with the correct settings it is now time to start up postfix. This can be achieved from the command line as follows:

/usr/sbin/postfix start

The postfix process should now start up. The best way to check that everything is working is to check your mail log. This is typically in /var/log/maillog and should now contain an entry that looks like:

Apr 29 12:57:36 mylinuxhost postfix/postfix-script[22793]: starting the Postfix mail system
Apr 29 12:57:36 mylinuxhost postfix/master[22794]: daemon started -- version 2.6.6, configuration /etc/postfix

As long as you don’t see any error messages you have successfully installed and started Postfix and you are ready to set up a mail client and start communicating with the outside world.

To configure Postfix to start automatically at system startup, run the following command in a Terminal window:

/sbin/chkconfig --level 345 postfix on

Editing PHP configuration file

Edit /etc/php.ini and change the line that contains sendmail_path with the following:

sendmail_path = /usr/sbin/sendmail.postfix -t -i

Reload Apache

/sbin/service httpd reload

Reference:

http://www.techotopia.com/index.php/Configuring_a_CentOS_6_Postfix_Email_Server
http://drupal.org/node/321857#comment-1063535
Advertisements

2 thoughts on “How to Install Postfix on CentOS 6

  1. I blog frequently and I truly appreciate your information.
    The article has really peaked my interest. I’m going to take a note of your site and keep checking for new details about once per week. I subscribed to your Feed too.

  2. Have you ever considered writing an ebook or guest authoring
    on other websites? I have a blog based upon on the
    same ideas you discuss and would love to have you share some stories/information.

    I know my audience would value your work. If you are even remotely interested, feel free to send me an email.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s