The Perfect Server - CentOS 6.3 x86_64 (nginx, Dovecot, ISPConfig 3) - Page 4

11 Install Dovecot

Dovecot can be installed as follows:

yum install dovecot dovecot-mysql

Now create the system startup links and start Dovecot:

chkconfig --levels 235 dovecot on
/etc/init.d/dovecot start


12 Install Postfix

Postfix can be installed as follows:

yum install postfix

Then turn off Sendmail and start Postfix:

chkconfig --levels 235 sendmail off
chkconfig --levels 235 postfix on
/etc/init.d/sendmail stop
/etc/init.d/postfix restart


13 Install Getmail

Getmail can be installed as follows:

yum install getmail


14 Install Amavisd-new, SpamAssassin, And ClamAV

To install amavisd-new, spamassassin and clamav, run the following command:

yum install amavisd-new spamassassin clamav clamd unzip bzip2 unrar perl-DBD-mysql

Then we start freshclam, amavisd, and clamd.amavisd:

chkconfig --levels 235 amavisd on
chkconfig --del clamd
chkconfig --levels 235 clamd.amavisd on
/etc/init.d/amavisd start
/etc/init.d/clamd.amavisd start


15 Install Nginx, PHP5 (PHP-FPM), And Fcgiwrap

Nginx is available as a package for CentOS 6.3 (from EPEL) which we can install as follows:

yum install nginx

If Apache2 is already installed on the system, stop it now...

/etc/init.d/httpd stop

... and remove Apache's system startup links:

chkconfig --del httpd

Then we create the system startup links for nginx and start it:

chkconfig --levels 235 nginx on
/etc/init.d/nginx start

(If both Apache2 and nginx are installed, the ISPConfig 3 installer will ask you which one you want to use - answer nginx in this case. If only one of these both is installed, ISPConfig will do the necessary configuration automatically.)

We can make PHP5 work in nginx through PHP-FPM (PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites). We can install php-fpm together with php-cli and some PHP5 modules like php-mysql which you need if you want to use MySQL from your PHP scripts as follows:

yum install php-fpm php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-pecl-apc php-magickwand php-magpierss php-mbstring php-mcrypt php-mssql php-shout php-snmp php-soap php-tidy

Next we open /etc/php.ini...

vi /etc/php.ini

... and change the error reporting (so that notices aren't shown any longer):

;error_reporting = E_ALL & ~E_DEPRECATED
error_reporting = E_ALL & ~E_NOTICE

Also set cgi.fix_pathinfo=0:

vi /etc/php.ini

; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI.  PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is.  For more information on PATH_INFO, see the cgi specs.  Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec.  A setting
; of zero causes PHP to behave as before.  Default is 1.  You should fix your scripts

(Please read to find out why you should do this.)

In addition to that, in order to avoid errors like

[08-Aug-2011 18:07:08] PHP Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /usr/share/nginx/html/info.php on line 2

... in /var/log/php-fpm/www-error.log when you call a PHP script in your browser, you should set date.timezone in /etc/php.ini:

; Defines the default timezone used by the date functions
date.timezone = "Europe/Berlin"

You can find out the correct timezone for your system by running:

cat /etc/sysconfig/clock

[root@server1 tmp]# cat /etc/sysconfig/clock
[root@server1 tmp]#

Next create the system startup links for php-fpm and start it:

chkconfig --levels 235 php-fpm on
/etc/init.d/php-fpm start

PHP-FPM is a daemon process (with the init script /etc/init.d/php-fpm) that runs a FastCGI server on port 9000.

To get CGI support in nginx, we install Fcgiwrap.

Fcgiwrap is a CGI wrapper that should work also for complex CGI scripts and can be used for shared hosting environments because it allows each vhost to use its own cgi-bin directory.

As there's no fcgiwrap package for CentOS 6.3, we must build it ourselves. First we install some prerequisites:

yum install fcgi-devel

Now we can build fcgiwrap as follows:

cd /usr/local/src/
git clone git://
cd fcgiwrap
autoreconf -i
make install

This installs fcgiwrap to /usr/local/sbin/fcgiwrap.

Next we install the spawn-fcgi package which allows us to run fcgiwrap as a daemon:

yum install spawn-fcgi

Open /etc/sysconfig/spawn-fcgi...

vi /etc/sysconfig/spawn-fcgi

... and modify the file as follows:

# You must set some working options before the "spawn-fcgi" service will work.
# If SOCKET points to a file, then this file is cleaned up by the init script.
# See spawn-fcgi(1) for all possible options.
# Example :
#OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/ -- /usr/bin/php-cgi"


Now add the user nginx to the group apache:

usermod -a -G apache nginx

Create the system startup links for spawn-fcgi...

chkconfig --levels 235 spawn-fcgi on

... and start it as follows:

/etc/init.d/spawn-fcgi start

You should now find the fcgiwrap socket in /var/run/fcgiwrap.socket, owned by the user and group apache (some scripts, e.g. Mailman, expect to be run by the user/group apache, that's why we don't run spawn-fcgi as user/group nginx, but instead add nginx to the apache group).

Share this page:

2 Comment(s)

Add comment


From: Newbie at: 2012-08-18 11:51:38

Is it possible to have the above setup used with Centos 6.0?

Centos 6.0 +  Nginx + Mysql + PHP + ISPconfig 3.

From: at: 2013-01-10 06:33:01

I think it should be fine for CentOS 6.0