Install Nginx PHP-FPM and Varnish on CentOS

nginx-varnish

First of all download and install the remi repo

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh epel-release-6-8.noarch.rpm remi-release-6.rpm

Now Installed the php with common used modules and php-fpm

yum --enablerepo=remi install php php-fpm php-common php-mysql php-pdo php-pecl-apc php-cli php-mcrypt php-xml php-gd php-mbstring

Now Install the nginx

yum install nginx

Now edit the php-fpm configuration file /etc/php-fpm.d/www.conf and change the user and group to nginx.

;listen = 127.0.0.1:9000
listen = /var/run/php-fpm/php-fpm.sock
;user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache
group = nginx

Edit he nginx configuration file /etc/nginx/conf.d/default.conf and set the the port to 8080 and set correct path to php-fpm socket file

listen       8080; 
location ~ \.php$ {
      root   /usr/share/nginx/html;
      fastcgi_split_path_info  ^(.+\.php)(.*)$;
      fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index  index.php;
      fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
      include fastcgi_params;
}

Install varnish

rpm -Uvh http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.noarch.rpm
yum install varnish

Edit varnish configuration file /etc/sysconfig/varnish and set the port to 80

VARNISH_LISTEN_PORT=80

Now you are ready to go, start the php-fpm, nginx and varnish

service php-fpm start
service nginx start
service varnish start

About 

Sreejit is the founder of Server Management Plus. He has created a lots of automation scripts for the company using which we are able to resolve issue at an extremely fast rate and save lots of time. He has a very keen interest in new technologies and spend most of his free time online researching about it apart from listening music and watching movies.