Setup Nginx PHP FPM Percona Mysql

From Brian Nelson Ramblings
Revision as of 01:49, 9 February 2014 by Brian (Talk | contribs) (4) Configure Nginx to use PHP+FPM)

Jump to: navigation, search

Setup Nginx + php-fpm + Percona Mysql

First we will want to enable the epel repo and percona repos

rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
rpm -Uhv http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

1) Install Percona Mysql

Lets install Percona56 Server

yum install Percona-Server-server-56 Percona-Server-client-56

To increase performance of INNODB tables lets create separate namespaces

vim /etc/my.cnf

Now add the following line under [mysqld]

[mysqld]
innodb_file_per_table

Lets make sure Percona starts on boot

chkconfig mysql on

Lets Start Percona Server

/etc/init.d/mysql restart

2) Install Nginx

yum install nginx -y

Let nginx to start on boot

chkconfig nginx on

Now lets start nginx

/etc/init.d/nginx start

3) Install PHP-FPM/PHP-CLI

Lets install php-fpm with Yum

yum install php-fpm php-mysql php-mssql

Start php-fpm at boot up

chkconfig php-fpm on

/etc/init.d/php-fpm start

Lets check and make sure there is no issues with php-fpm

php-fpm -v
PHP 5.3.3 (fpm-fcgi) (built: Dec 11 2013 03:17:57)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

If you want the default php -v via the command line we can create a symlink

ln -s /usr/sbin/php-fpm /usr/sbin/php

4) Configure Nginx to use PHP+FPM

First thing we need to do is change the cgi.fix_pathinfo

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php.ini

If this number is kept as 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.

Now restart php-fpm so it takes

/etc/init.d/php-fpm restart

PHP+FPM TCP

PHP+FPM Socket