Install Configure VSFTPD on CentOS 6

First please make sure to update CentOS 6 systems with the current files with command yum -y update

#yum -y update
Loaded plugins: fastestmirror
Setting up Update Process
base | 3.7 kB 00:00
base/primary_db | 4.7 MB 00:04

Then move forward to install VSFTPD with any required packages with yum -y install vsftpd

#yum -y install vsftpd
Loaded plugins: fastestmirror
Setting up Install Process
Determining fastest mirrors
* base: mirror.ventraip.net.au
* extras: mirror.ventraip.net.au
* updates: mirror.ventraip.net.au
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-21.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved

After VSFTPD installation has been complete, now edit and configure vsftpd.conf file

#vi /etc/vsftpd/vsftpd.conf
# Allow anonymous FTP (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list

Exit and save the file with command :wq
Then restart the vsftpd service with command service vsftpd restart

#service vsftpd restart

Set the vsftpd service to start at boot with command chkconfig vsftpd on

#chkconfig vsftpd on

Add VSFTPD user

# useradd user
# passwd user
Changing password for user user.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

You will need to create a vsftp.chroot_list file and enter users who do not use chroot. Ever user chroots by default. Therefore, create a chroot_list file, even if the file is going to remain empty:

#touch /etc/vsftpd/vsftpd.chroot_list

Once the vsftpd.chroot_list file has been created, restart vsftpd again

#service vsftpd restart

Test VSFTPD user log in to FTP Server with ftp client application, this example using FileZilla

Install WordPress on Nginx CentOS Server

Before to install Wordpress online on Nginx CentOS Server, we should verify that NGINX MySQL PHP (LEMP) has been installed and all of the LEMP services are started and running.

The most important thing is Nginx WordPress configuration for domain.tld. Assume domain.ltd has been configured as virtual host on our server, edit virtual.conf and insert configuration below:

#vi /etc/nginx/conf.d/virtual.conf
# Upstream to abstract backend connection(s) for php
upstream php {
server unix:/tmp/php-cgi.socket;
server 127.0.0.1:9000;
}

server {
listen 80;
## Your website name goes here (servername example.com www.example.com).
server_name domain.tld;
## Your only path reference.
root /var/www/example.com/public_html;
## This should be in your http block and if it is, it's not needed here.
index index.php;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}

location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi.conf;
fastcgi_intercept_errors on;
fastcgi_pass php;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
#Fix Yoast SEO Sitemaps
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
}

Save and Exit then Restart nginx and php-fpm service again so that all of the changes take effect:

#service nginx restart
#service php-fpm restart

Step one: Download WordPress directly from their website.

Make sure current directory is /var/www/example.com/public_html

#cd /var/www/example.com/public_html
#wget http://wordpress.org/latest.tar.gz

Unzip it the the next line:

#tar -xzvf latest.tar.gz

After we unzip the wordpress files, they will be in a directory called wordpress in the current directory.
Copy all files and folder on that wordpress directory to /var/www/example.com/public_html

#cp -R wordpress/* /var/www/example.com/public_html

We will need to create an /upload directory on /var/www/wp-content/ folder so we can make contents and upload files into it.

#mkdir -p /var/www/wp-content/uploads

Grant Ownership Permissions of directory to user

#chown -R user:nginx /var/www/example.com/public_html

Step Two: Create the WordPress Database and User.

#mysql -u root -p
mysql>CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

Then we need to create the new user. You can replace the database, name, and password

mysql>CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Finish up by granting all privileges to the new user.

mysql>GRANT ALL PRIVILEGES ON wpdb.* TO 'wpuser'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

Then refresh MySQL:

mysql>FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Exit out of the MySQL shell:

exit

Step Three Setup the WordPress Configuration
The first step to is to copy the sample wordpress configuration file (wp-config-sample.php) into a new file wp-config.php which we will edit,  assume current working directory is /var/www/example.com/public_html;

#cd /var/www/example.com/public_html
#cp wp-config-sample.php wp-config.php

Then open the wordpress config:

#vi wp-config.php

Find the section that contains the field below and substitute in the correct name for your database, username, and password:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wpdb');

/** MySQL database username */
define('DB_USER', 'wpuser');

/** MySQL database password */
define('DB_PASSWORD', 'password');
Save and Exit.

 

From here, WordPress has its own easy to follow installation form online. However, the form does require a specific php module to run. If it is not yet installed on your server, download php-gd:

#yum install php-gd

Restart nginx and php-fpm service again so that all of the changes take effect:

#service httpd restart

Step Five RESULTS Access the WordPress Installation
Access the page by adding /wp-admin/install.php to your site’s domain or IP address (eg. example.com/wp-admin/install.php) and fill out the short online form

Add new User Group on CentOS 6 terminal

To add a New User and Assign a Group on CentOS 6 terminal

#useradd -g <groupname> username

For instance, lets say you wanted to add a new user named user to the apache group:

#useradd -G apache user

And then you’ll want to assign a password for that user, of course:

passwd user

Add or update User to an an Group

#usermod -a -G <groupname> username

Change a User Primary Group

Sometimes a user has many group, this is switch out the primary group that a user is assigned to with this command:

#usermod -g <groupname> username

View a User Group Assignments by use the id command to see what groups the user is assigned to:

id <username>

This will display output something like this:

uid=500(howtogeek) gid=500(howtogeek) groups=500(howtogeek), 1093(admins)

 

Import Export MySQL Dumpfile MySQL Server on Terminal

This is an alternative way to restore or import MySQL Dumpfile data with mysql command on Terminal.
Best tool to restore or import MySQL Dumpfile is phpMyAdmin, here is the tutorial to Set up Apache phpMyadmin and Nginx phpMyAdmin

This is restore or import dbuser.sql dumpfile into dbuser MySQL database using user as username:

First we upload MySQL dumpfile to terminal or home folder of user
Easy simple way by log in via SFTP (SSH File Transfer Protocol), this is same way a  user log via ssh. We can use Bitvise, Filezilla, etc.

Assume database ‘dbuser’ has been created and MySQL dumpfile (dbuser.sql) has been uploaded to user home folder, user log in to terminal and in home directory position.

#ls -la
dbuser.sql

Import: To MySQL dump data file to MySQL Server type the following command:

#pwd
/home/user
#mysql -u user -p -h localhost dbuser < dbuser.sql

Export: To Export a database and create dump file from MySQL Server type the following command:

#mysqldump -u [username] -p [database name] > [database name].sql

Install phpMyadmin Nginx CentOS 6

Prior to installing phpMyAdmin, we should verify that NGINX MySQL PHP (LEMP) has been installed and all of the LEMP services are started and running.  We can grep look for their processes – “nginx”, “mysqld” and “php-fpm”:

#ps auxf | egrep "nginx|mysqld|php-fpm"

If you see processes similar to the ones below, you may proceed with the phpMyAdmin installation, otherwise you need to get back to the LEMP setup tutorial:

[root@vpshelpdesk phpMyAdmin]# ps auxf | egrep "nginx|mysqld|php-fpm"
root 1171 0.0 0.2 2340 588 pts/0 S+ 15:01 0:00 | \_ gr ep -E nginx|mysqld|php-fpm
root 574 0.0 0.5 3044 1324 ? S 14:41 0:00 /bin/sh /usr/bin/mysqld_sa fe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/m ysqld.pid --basedir=/usr --user=mysql

Install phpMyadmin

#wget https://files.phpmyadmin.net/phpMyAdmin/4.1.7/phpMyAdmin-4.1.7-all-languages.zip
#unzip phpMyAdmin-4.1.7-all-languages.zip
#mv phpMyAdmin-4.1.7-all-languages.zip phpMyAdmin
#mv phpMyAdmin /usr/share/nginx/html
#cd /usr/share/nginx/html/phpMyAdmin
#service nginx restart
#service php-fpm restart

Check the result http://ipaddress/phpMyAdmin
phpMyadmin page will appear but this still not work, we should edit phpMyadmin config.ing.php

#cd /usr/share/nginx/html/phpMyAdmin/
#mv config.sample.inc.php config.inc.php
#vi /usr/share/nginx/html/phpMyAdmin/config.ing.php
Edit following lines:
$cfg['Servers'][$i]['auth_type'] = 'cookie';
With this:
$cfg['Servers'][$i]['auth_type'] = 'http';
#service nginx restart
#service php-fpm restart

Check the result again http://ipaddress/phpMyAdmin
It will work!

Setup Nginx Virtual Host on CentOS 6

Assume NGINX MySQL PHP (LEMP) has been success installed on CentOS 6, for tutorial how to install visit here

Create a New Directory for web files
The first step in creating a virtual host is to a create a directory where we will keep the new website’s information. This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code that allows us to create a folder with a nested folder inside of it

#mkdir -p /var/www/example.com/public_html

Grant Ownership Permissions of directory to user (assumed username ‘user’ has been added)

#chown -R user:nginx /var/www/example.com/public_html

Additionally, it is important to make sure that everyone will be able to read our new files.

#chmod 755 /var/www

Create index html page to for test within our configurations directory.

#vi /var/www/example.com/public_html/index.html
<html>
<head>
<title>www.example.com</title>
</head>
<body>
<h1>Success: You Have Set Up a Virtual Host</h1>
</body>
</html>

Turn on Nginx Virtual Host
To setup nginx virtual host, we will need to open up nginx virtual file located at /etc/nginx/conf.d/virtual.conf and you will need to update it with the following configuration

#vi /etc/nginx/conf.d/virtual.conf
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/public_html;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Logging -- access_log /var/www/example.com/public_html/access.log; error_log /var/www/example.com/public_html/error.log; # serve static files directly location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ { access_log off; expires max; } }

Restart nginx and php-fpm service

#service nginx restart

Setting Up the Local Hosts
If you have pointed your domain name to your virtual private server’s IP address you can skip this step. You do not need to set up local hosts. Your virtual hosts should work. However, if want to try out your new virtual hosts without having to connect to an actual domain name, you can set up local hosts on your computer alone.

#vi /etc/hosts
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
#Virtual Hosts
12.34.56.789 www.example.com

Test if nginx virtual host has been working by access this at browser http://example.com

Enable PHP
To enable PHP please add following line to /etc/nginx/conf.d/virtual.conf

#vi /etc/nginx/conf.d/virtual.conf
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/example.com/public_html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

CHECK RESULTS:
Create a php info page and add in the following line:

#vi /var/www/example.com/public_html/info.php
<?php
phpinfo();
?>

Then Save and Exit.
Restart nginx and php-fpm service again so that all of the changes take effect:

#service nginx restart
#service php-fpm restart

Test if php working by access this at browser http://example.com/info.php

Install NGINX MySQL PHP (LEMP) on CentOS 6

To avoid any conflict once NGINX service start please make sure Apache service already removed (if available). We can remove Apache service as follow
Shutdown Apache service (if running)

#service httpd stop

Remove Apache from the boot cycle, so that it does not start up again on server boot

#chkconfig httpd off

Remove Apache package

#yum remove httpd

STEP ONE: UPDATE EPEL REPOSITORY

NGINX is available as a package for CentOS 6 from epel repository but first we should update epel repository, which we can install as follows:

#yum install epel-release

STEP TWO: INSTALL MYSQL

MySQL is a powerful database management system used for organizing and retrieving data on a virtual server. To install MySQL, open terminal and type in these commands:

#yum install mysql-server
#service mysql start

During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install. Once it is done installing, you can set a root MySQL password:

#/usr/bin/mysql_secure_installation

The prompt will ask you for your current root password. Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.

Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
Remove anonymous users? [Y/n] y
 ... Success!
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

Set the processes to run automatically when server boots

#chkconfig mysql on

STEP THREE: INSTALL NGINX

Nginx install using yum

#yum install nginx

To get NGINX running type:

#/etc/init.d/nginx start

We can check that nginx has installed by open a browser and type http://ipaddressNGINX-success-installed
Configure the server to start NGINX on server boot

#chkconfig nginx on

STEP FOUR: INSTALL PHP
The php-fpm package is located within the REMI repository, which, at this point, is disabled. The first thing we need to do is enable the REMI repository and install php and php-fpm:

#wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
#rpm -Uvh remi-release-6.rpm

Enable REMI repository by edit file remi.repo.
Find the line enabled =0 and change all of it to 1 to enable REMI repository.

#vi /etc/yum.repos.d/remi.repo
[...]
enabled=1
[...]

Then we can install php and php-fpm as follows:

#yum install php-fpm php-mysql

Set the php-fpm processes to run automatically when server boots

#service php-fpm start
#chkconfig php-fpm on

STEP FIVE: CONFIGURE PHP
We need to make one small change in the php.ini configuration.
Find the line, cgi.fix_pathinfo=1, and change the 1 to 0

#vi /etc/php.ini
cgi.fix_pathinfo=0

If this number is kept as a 1, the php interpreter will do its best to process the file that is as near to the requested file as possible. This is a possible security risk. If this number is set to 0, conversely, the interpreter will only process the exact file path a much safer alternative. Save and Exit.

STEP SIX: CONFIGURE NGINX
Open up the default nginx config file and raise the number of worker processes to 4 then save and exit that file.

#vi /etc/nginx/nginx.conf
[...]
worker_processes  4;
[...]

Nginx already comes with a default configuration to use php fpm. Open the /etc/nginx/conf.d/default.conf file and look following lines.

#vi /etc/nginx/conf.d/default.conf
# The default server
server {
    listen       80;
    server_name example.com;
 
    location / {
        root   /usr/share/nginx/html;
        index index.php  index.html index.htm;
    }
 
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Here are the details of the changes:

  • Add index.php within the index line.
  • Change the server_name to your domain name or IP address (replace the example.com in the configuration)
  • Change the root to /usr/share/nginx/html;
  • Uncomment the section beginning with “location ~ \.php$ {“,
  • Change the root to access the actual document root, /usr/share/nginx/html;
  • Change the fastcgi_param line to help the PHP interpreter find the PHP script that we stored in the document root home.
  • Save and Exit

Open up the php-fpm configuration, replace the apache in the user and group with nginx:

#vi /etc/php-fpm.d/www.conf
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

Finish by restarting php-fpm.

#service php-fpm restart

CHECK RESULTS:
Create a php info page and add in the following line:

#vi /usr/share/nginx/html/info.php
<?php
phpinfo();
?>

Then Save and Exit.
Restart nginx so that all of the changes take effect:

#service nginx restart

We can check that NGINX MySQL PHP has installed successfully by open a browser and type http://ipaddress/info.php

Set Up nginx, mysqld, php-fpm Autostart

#chkconfig --levels 235 mysql on
#chkconfig --levels 235 nginx on
#chkconfig --levels 235 php-fpm on

How to zip unzip file folder on CentOS terminal

By default zip unzip are not installed on CentOS, so we have to install it

[root@vpshelpdesk]# yum install zip
Loaded plugins: fastestmirror
Setting up Install Process
[root@vpshelpdesk]# yum install unzip
Loaded plugins: fastestmirror
Setting up Install Process

Compress files error.log to error.zip in current directory

[root@vpshelpdesk]zip error.zip error.log

Compress entire files, folder but not including all subdirectories to data.zip in current directory

[root@vpshelpdesk]#zip data.zip *

Compress entire files, folder, all subdirectories and hidden files to data.zip

[root@vpshelpdesk]#zip -r data.zip .* -x "../*"

To uncompress or extract data.zip

[root@vpshelpdesk]#unzip data.zip

You can also test data.zip, printing only a summary message indicating whether the archive is OK or not:

[root@vpshelpdesk]#unzip -tq data.zip

To extract the file called file.txt from data.zip:

[root@vpshelpdesk]#unzip data.zip  file.txt

To extract all files into the /tmp directory:

[root@vpshelpdesk]#unzip data.zip  -d /tmp

To list all files from data.zip:

[root@vpshelpdesk]#unzip -l data.zip

To move all folder and files

#mv /sourcefolder/{,.[^.]}* /destinationfolder/

Set Up Postfix Local Mail Server, Dovecot, Squirrelmail On CentOS 6

This article describe how to set up and configure Postfix Mail Server with Dovecot and Squirrelmail On CentOS 6 at Local Area Network.

Set up and configure Postfix Mail Server to receive and send email on public area network (internet) with domain name ([email protected]) is very complex and difficult to set up, need much resources like static public ip address, stable server, etc.
As an alternative we can set up and configure Postfix to use Gmail as a Mail Relay, only need a Postfix Mail Server installed and a Gmail account  to configure MTA to relay outgoing mail through Gmail.

Postfix is a free open source mail transfer agent (MTA).

Dovecot is an open source IMAP and POP3 mail server for Unix/Linux systems.

SquirrelMail is a standards-based webmail package written in PHP support for the IMAP and SMTP protocols, and all pages render in pure HTML 4.0 (with no JavaScript required) for maximum compatibility across browsers.

It is important to disabled SELinux to reduce complexity in postfix configuration.
Remove default MTA sendmail first if it’s already installed

# yum remove sendmail

Add hostname entries in /etc/hosts file as shown below:

# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain
::1 localhost localhost.localdomain
192.168.1.101 server.vpshelpdesk.local vpshelpdesk

Install Postfix package using the command:

# yum install postfix -y

Configuring Postfix, Edit /etc/postfix/main.cf,

# vi /etc/postfix/main.cf

find and edit the following lines:

## Line no 75 - Uncomment and set your mail server FQDN ##
myhostname = vpshelpdesk.local
## Line 83 - Uncomment and Set domain name ##
mydomain = vpshelpdesk
## Line 99 - Uncomment ##
myorigin = $mydomain
## Line 116 - Set ipv4 ##
inet_interfaces = all
## Line 119 - Change to all ##
inet_protocols = all
## Line 164 - Comment ##
#mydestination = $myhostname, localhost.$mydomain, localhost,
## Line 165 - Uncomment ##\
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## Line 264 - Uncomment and add IP range ##
mynetworks = 192.168.1.0/24, 127.0.0.0/8
## Line 419 - Uncomment ##
home_mailbox = Maildir/

Save and exit the file. Start/restart Postfix service now:

# service postfix restart
# chkconfig postfix on

Testing Postfix mail server
First, create a test user called “SK“.

# useradd sk
# passwd sk

Access the server via Telnet and enter the commands manually shown in ## ##

# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 vpshelpdesk.local ESMTP Postfix
ehlo localhost ## type this command ##
250-server.vpshelpdesk.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<sk> ## Type this - mail sender address##
250 2.1.0 Ok
rcpt to:<sk> ## Type this - mail receiver address ##
250 2.1.5 Ok
data ## Type this to input email message ##
354 End data with <CR><LF>.<CR><LF>
welcome to vpshelpdesk mail server ## Enter the body of the email ##.
## type dot (.) to complete message ##
250 2.0.0 Ok: queued as B822221522
quit ## type this to quit from mail ##
221 2.0.0 Bye
Connection closed by foreign host.

Now navigate to the user “sk“ mail directory and check for the new mail:

# ls /home/sk/Maildir/new/
Sample output:

1390215275.Vfd00Ie04f8M357080.vpshelpdesk.local
A new mail is received to the user “sk“. To read the mail, enter the following command:
# cat /home/sk/Maildir/new/1390215275.Vfd00Ie04f8M357080.mail.local
Sample output:
Return-Path: <[email protected]>
X-Original-To: sk
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by mail.local (Postfix) with ESMTP id B822221522
for <sk>; Mon, 20 Jan 2014 16:23:54 +0530 (IST)
Message-Id: <[email protected]>
Date: Mon, 20 Jan 2014 16:23:54 +0530 (IST)
From: [email protected]
To: undisclosed-recipients:;
welcome to vpshelpdesk mail server

Installing Dovecot
Dovecot is an open source IMAP and POP3 mail server for Unix/Linux systems. To install:

# yum install dovecot

Configuring Dovecot
Edit the file /etc/dovecot/dovecot.conf file,

#vi /etc/dovecot/dovecot.conf

Uncomment the following line:

## Line 20 - umcomment ##
protocols = imap pop3 lmtp

Edit file /etc/dovecot/conf.d/10-mail.conf file

#vi /etc/dovecot/conf.d/10-mail.conf

Make the changes as shown below:

## Line 24 - uncomment ##
mail_location = maildir:~/Maildir

Edit /etc/dovecot/conf.d/10-auth.conf

#vi /etc/dovecot/conf.d/10-auth.conf

And make the changes as shown below:

## line 9 - uncomment##
disable_plaintext_auth = yes
## Line 97 - Add a letter "login" ##
auth_mechanisms = plain login

Edit file /etc/dovecot/conf.d/10-master.conf,

# vi /etc/dovecot/conf.d/10-master.conf

Make changes as shown below:

## Line 83, 84 - Uncomment and add "postfix"
#mode = 0600
user = postfix
group = postfix

Start Dovecot service:

# service dovecot start
# chkconfig dovecot on

Testing Dovecot
It’s time to test Dovecot configuration. Enter the following command in Terminal:

#telnet localhost pop3
Enter the commands manually marked in red color:
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user sk ## log in as user sk ##
+OK
pass centos ## input user password ##
+OK Logged in.
retr 1
+OK 439 octets
Return-Path: <[email protected]>
X-Original-To: sk
Delivered-To: [email protected]
Received: from localhost (localhost [IPv6:::1])
by server.vpshelpdesk.local (Postfix) with ESMTP id B822221522
for <sk>; Mon, 20 Jan 2014 16:23:54 +0530 (IST)
Message-Id: <[email protected]>
Date: Mon, 20 Jan 2014 16:23:54 +0530 (IST)
From: [email protected]
To: undisclosed-recipients:;
welcome to vpshelpdesk mail server
.
quit
+OK Logging out.
Connection closed by foreign host.

Good Dovecot is working!

Installing Squirrelmail
Make sure that you’ve installed and enabled EPEL repository. Now install Squirrelmail using the following command:

#yum install squirrelmail

Configuring Squirrelmail
Navigate to /usr/share/squirrelmail/config/ directory and run the command conf.pl:

# cd /usr/share/squirrelmail/config/
# ./conf.pl

The following wizard will open. Enter choice “1” to set your organization details:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 1
The following wizard will open. Enter “1” again to modify your organization details:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : SquirrelMail
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://squirrelmail.org/
8. Provider name : SquirrelMail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
Set your Organization name and press Enter:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Organization Preferences
1. Organization Name : vpshelpdesk
2. Organization Logo : ../images/sm_logo.png
3. Org. Logo Width/Height : (308/111)
4. Organization Title : SquirrelMail $version
5. Signout Page :
6. Top Frame : _top
7. Provider link : http://squirrelmail.org/
8. Provider name : vpshelpdesk Mail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> s
Now enter “2” to setup mail Server settings such as domain name and mail agent etc.:

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 2
Enter “1”, Enter your mail domain (ex. vpshelpdesk. local) and press Enter key.

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : localhost
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 1
The domain name is the suffix at the end of all email addresses. If
for example, your email address is [email protected], then your domain
would be example.com.
[localhost]: unixmen.local
Enter “3” and change from sendmail to Postfix MTA (i.e. SMTP):

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1. Domain : unixmen.local
2. Invert Time : false
3. Sendmail or SMTP : Sendmail
A. Update IMAP Settings : localhost:143 (uw)
B. Change Sendmail Config : /usr/sbin/sendmail
R Return to Main Menu
C Turn color off
S Save data
Q Quit
Command >> 3
Enter “2” to switch from sendmail MTA to postfix.

You now need to choose the method that you will use for sending
messages in SquirrelMail. You can either connect to an SMTP server
or use sendmail directly.
1. Sendmail
2. SMTP
Your choice [1/2] [1]: 2
Now enter “S” followed by “Q” to save and exit Squirrelmail configuration.

Create a squirrelmail vhost in apache config file:

#vi /etc/httpd/conf/httpd.conf
Add the following lines at the end:
Alias /webmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
Options Indexes FollowSymLinks
RewriteEngine On
AllowOverride All
DirectoryIndex index.php
Order allow,deny
Allow from all
</Directory>

Restart the Apache service:

#service httpd restart

Create users
Create some users for testing. In my case i create two users called “senthil“ and “kumar“ respectively.

# useradd senthil
# useradd kumar
# passwd senthil
# passwd kumar

Access Webmail
Now navigate to http://ip-address/webmail or http://domain-name/webmail from your browser. The following screen should appear. Enter the username and password of the user.

Now you’ll be able to access the user senthil mail box. Let us compose a test mail from user “senthil“ to user “kumar“. Click on the Compose link on the top. Enter the recipient mail id (ex. [email protected]), subject and body of the mail and click Send.

Now log out from user “senthil“ and log in to user “kumar“ mail and check for any new mail.

Hurrah! We have got a new mail from [email protected] mail id. To read the mail, click on it. You’ll now be able to read, reply, delete or compose a new mail.

That’s it for now. We’ve successfully configured a local mail server that will serve in/out mails within a local area network. But i want to configure a public mail server to send and receive mails to outside of our LAN, what should i do? That’s not that difficult either.

You should configure mail server with a public IP and request your ISP to put the MX record of your mail server into their DNS server and you’re done! Everything will be same as i described above.

Setup DNS server and add the Mail server MX records in the forward and reverse zone files. To install and configure DNS server, navigate to this link. And you’ll need to contact your ISP to point your external static IP to your mail domain.

This article taken from http://www.unixmen.com/install-postfix-mail-server-with-dovecot-and-squirrelmail-on-centos-6-4/

Set up Postfix Gmail SMTP Relay on CentOS 6

This article describe how to Set up and Configure Postfix Gmail SMTP Relay on CentOS 6, we will set up Gmail as a Mail Relay, a Gmail account must ready to configure MTA to relay outgoing mail through Gmail.
Postfix is an MTA (Mail Transfer Agent), an application used to send and receive email.
GMail is a free web-based email service by Google with reliability and robust infrastructure who provides a simple sending email from the command line with smtp.gmail.com:587.

We Assume a website have contact form php page for visitor to send message. Postifx Mail Transfer Agent will deliver the message to recipient but guarantee the message will mark as spam. But if Postifx configure to use GMail as SMTP Relay, the message will send by Gmail account which already set up and configure on Postifx, so far the message will store at inbox not spam.

Install Postfix, make sure SASL authentication framework, and mailx also installed.
First Remove default MTA sendmail first if it’s already installed, make sure postfix as default MTA

#yum remove sendmail
#yum install postfix cyrus-sasl-plain mailx -y

Postfix will need to be start before the SASL framework will be detected.

#service postfix start

If error occurred postfix failed to start

Starting postfix:                                          [FAILED]
#tail -f /var/log/maillog
postfix[1070]:fatal:config variable inet_interfaces:host not found:localhost

Change the inet_interfaces setting in /etc/postfix/main.cf from:

inet_interfaces = localhost inet_interfaces = 127.0.0.1

Postfix should also be set to start on boot.

#chkconfig postfix on

Check that Postfix configured with SSL support (ie. ldd should return at least one line starting with libssl):

#whereis -b postfix
postfix: /usr/sbin/postfix /etc/postfix /usr/libexec/postfix
#ldd /usr/sbin/postfix
libssl.so.6 => /lib/libssl.so.6 (0x00111000)

Find your server’s CA root certificate bundle path, which is typically distributed with openssl. The bundle file is used by Postfix to verify Gmail’s SSL certificate (signed by Thawte).

#locate ca-bundle.crt
/etc/ssl/certs/ca-bundle.crt

Then edit /etc/postfix/main.cf, simply add/paste the following lines to the end of the file.

#vi /etc/postfix/main.cf
myhostname = hostname.example.com
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous

The myhostname is optional. If hostname is not specified, Postfix will use the fully-qualified domain name of the server.

Configure Postfix SASL Credentials
The Gmail credentials must now be added for authentication. Create a /etc/postfix/sasl_passwd file and add following line:

#vi /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 username:password

The username and password values must be replaced with valid Gmail credentials.
A Postfix lookup table must now be generated from the sasl_passwd text file by running the following command.

#postmap /etc/postfix/sasl_passwd

Access to the sasl_passwd files should be restricted.

#chown root:postfix /etc/postfix/sasl_passwd*
#chmod 640 /etc/postfix/sasl_passwd*

Lastly, reload the Postfix configuration.

#service postfix restart

Test the Relay
Use the mail command to test the relay.

echo "This is a test." | mail -s "test message" [email protected]

The destination address should receive the test message.
Troubleshoot Delivery Issues
The maillog can be reviewed if the test message is not successfully delivered. Open another shell and run tail while performing another test.

tail -f /var/log/maillog

If there are not enough details in the maillog to determine the problem, then the debug level can be increased by adding the following lines to the /etc/postfix/main.cf.

debug_peer_list=smtp.gmail.com
debug_peer_level=3

The Postfix configuration must be reloaded after updating the main.cf file.

#service postfix restart

Remember to remove the debug settings when testing is complete. The verbose logs can have a negative impact on server performance.

PROBLEM or ERROR occurred and how to resolve them
Port 25 open by iptables firewall
Make sure port 25 open has been accept by iptables firewall, visit this article to Install and Set Up Iptables Firewall on Centos 6
Postfix Gmail SMTP Relay access denied

rcpt to: [email protected]
554 5.7.1 <[email protected]>: : Relay access denied

Your Google Account has been suspendedYour-Google-Account-has-been-suspended

Hi vpshelpdesk,
Google has suspended your Account, [email protected], because of a violation of our Terms of Service.

Please follow possible solution below, so far it is working for meallow-less-secure-apps-ON

Change the “allow less secure apps” setting to enable. This allows them to connect to the account again.
Insert and Verify Account recovery email and phoneVerify-Account-recovery-email-and-phone

If Gmail SMTP Relay rare to use and rare sign in sometimes the message will not deliver again. Once check tail -f /var/log/maillog, we will find error below;

May 16 14:31:43 vpsheldesk.com postfix/smtp[1096]: D738BA40BE0: to=, relay=smtp.gmail.com[74.125.138.109]:587, delay=31, delays=0.01/0.04/31/0, dsn=4.7.14, status=deferred (SASL authentication failed; server smtp.gmail.com[74.125.138.109] said: 534-5.7.14 Please log in via your web browser and?534-5.7.14 then try again.?534-5.7.14 Learn more at?534 5.7.14 https://support.google.com/mail/answer/78754 w190sm8732463ywa.39 - gsmtp)
Visit GMAIL HELP https://support.google.com/mail/answer/78754 and follow the instructions


Can’t sign in to my email app
If you’re using the wrong Gmail password on another email app, you might have these problems:

  • The app keeps asking for your username and password
  • You see an “invalid credentials” error message
  • You see a “web login required” error message

If you have these problems or can’t sign in, first check to make sure you’re using the right password.

Tip: Keep in mind that passwords are case-sensitive.
Troubleshoot sign-in problems
If you’re sure your password is right, try these tips:

  • If you’ve turned on 2-Step Verification for your account, you might need to enter an App password instead of your regular password.
  • Sign in to your account from the web version of Gmail at https://mail.google.com. Once you’re signed in, try signing in to the mail app again.
  • Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.
  • Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your account.
  • Make sure your mail app isn’t set to check for new email too often. If your mail app check for new messages more than once every 10 minutes, the app’s access to your account could be blocked.
  • Change your password according to our tips on creating a strong password.