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

11 Install Dovecot

Dovecot can be installed as follows:

yum install dovecot dovecot-mysql
mkdir /etc/dovecot
touch /etc/dovecot/dovecot-sql.conf
ln -s /etc/dovecot/dovecot-sql.conf /etc/dovecot-sql.conf

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:

sa-update
chkconfig --levels 235 amavisd on
chkconfig --del clamd
chkconfig --levels 235 clamd.amavisd on
/usr/bin/freshclam
/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.4 (from EPEL) which we can install as follows:

yum install nginx

Add the following section to the http {} section in /etc/nginx/nginx.conf (before any include lines) which determines if the visitor uses http or https and sets the $https variable accordingly - this is needed because the nginx version coming with CentOS is 1.0.15, and the $https variable was introduced in nginx in version 1.1.11, and ISPConfig makes use of this variable:

vi /etc/nginx/nginx.conf

[...]
http {
[...]
    ## Detect when HTTPS is used
    map $scheme $https {
      default off;
      https on;
    }
[...]
}
[...]

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 & ~E_STRICT
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
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://www.php.net/manual/en/ini.core.php#ini.cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]

(Please read http://wiki.nginx.org/Pitfalls 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:

[...]
[Date]
; Defines the default timezone used by the date functions
; http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone
date.timezone = "Europe/Berlin"
[...]

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

cat /etc/sysconfig/clock

[[email protected] tmp]# cat /etc/sysconfig/clock
ZONE="Europe/Berlin"
[[email protected] 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.4, 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://github.com/gnosek/fcgiwrap.git
cd fcgiwrap
autoreconf -i
./configure
make
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 :
#SOCKET=/var/run/php-fcgi.sock
#OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"

FCGI_SOCKET=/var/run/fcgiwrap.socket
FCGI_PROGRAM=/usr/local/sbin/fcgiwrap
FCGI_USER=apache
FCGI_GROUP=apache
FCGI_EXTRA_OPTIONS="-M 0770"
OPTIONS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi.pid -- $FCGI_PROGRAM"

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).

 

15.1 Additional PHP Versions

Starting with the ISPConfig 3.0.5, it is possible to have multiple PHP versions on one server (selectable through ISPConfig) which can be run through FastCGI and PHP-FPM. The procedure of building additional PHP versions on CentOS is described in this tutorial: How To Use Multiple PHP Versions (PHP-FPM & FastCGI) With ISPConfig 3 (CentOS 6.3)

Share this page:

9 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Anonymous

Before building fcgiwrap you need to install some tools first:

yum install autoconf automake libtool

 

By: Ivan

Hello, i found i small missing in your great tutorial. Before "cd /usr/local/src/
git clone git://github.com/gnosek/fcgiwrap.git"  you have to mention how git should be installed, because there is not git there and it does not work. thank you. Ivan.
 

 

By: selva

 I can open the directory src. But I can process this possion. PLease help me. THanks

git clone git://github.com/gnosek/fcgiwrap.git

By:

Use 'https' instead of 'git' as below.

git clone https://github.com/gnosek/fcgiwrap.git

By: Coupon Code Swap

If you plan on running Drupal or another CMS, you may want to include this in the html section while configuring the nginx.conf file to avoid getting 502 Bad Gateway errors:

 

vi /etc/nginx/nginx.conf

 

fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;

By: Anonymous

cp /etc/dovecot/dovecot-sql.conf /etc/

By:

Hi,

 Can anyone show me how to enable mod re_write for drupal and joomla site? I've search for a few days and nothing comes up. I have multiple sites running Drupal on LAMP, and now I'm trying to migrate these sites to LEMP with ISPConfig.

By:

You will end up with a very old version of nginx if you install from epel. To get the latest version, do this:

 vi /etc/yum.repos.d/nginx.repo

paste and save:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1
priority=10

yum update

chkconfig --levels 235 nginx on

/etc/init.d/nginx start

By: Arkadiusz Zug

If you would like to use newest version of postfix 2.11.* and MariaDB 10.* you can use Axivo repo:

 rpm -ivh --nosignature http://rpm.axivo.com/redhat/axivo-release-6-1.noarch.rpm

 Tested by me and working