How to Install Nginx and PHP-FPM for Wordpress via yum

This Configuration is for CentOS 6, it should also work on Centos 5 although I have not tried it. This guide is for those who have basic linux command line knowledge.

I use atomic repo, as they have the latest updates, you can use epel, the choice is yours. But if there is any vulnerability then you will have to manually compile the patch

Step 1: Add Atomic Repo

wget -q -O - | sh
yum update

Step 2: Install Nginx

yum install nginx

Step3: Configure Nginx

Open Nginx conf file vim /etc/nginx/nginx.conf
Modify the Below lines, the number of processes depends on your CPU cores so if you have 2 then it should be 2 and the number of connections depend on your RAM, For a 2 core cpu with 750MB ram you can add the below config

worker_processes 2;
worker_connections 1024;
keepalive_timeout 5;

Keep alive should be as less as possible so that connections do not take up memory.

Next add the below line

include /etc/nginx/sites-enabled/*.conf;

Step 4: make 2 directories in /etc/nginx/

mkdir sites-available
mkdir sites-enabled

Create a file with named in sites-available and add the below config to it

server {
listen *:80;
error_log /var/log/nginx/;
access_log /var/log/nginx/ main;
root /home/sites/;
location / {
index index.php index.html index.htm;
#Permalink redirect
location /wordpress {
index index.php index.html index.htm;
try_files $uri $uri/ /wordpress/index.php?$args;
# force to use witout 'www'
if ($host = '' ) {
rewrite ^/(.*)$$1 permanent;
if ($host = '' ) {
rewrite ^/(.*)$ permanent;
# return 301 "${uri}";
# get friendly url links working
# if (!-e $request_filename)
# {
# rewrite ^(.+)$ /index.php?q=$1 last;
# pass all PHP files through php-fpm
location ~ .php$ {
#root /home/sites/;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/sites/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
# deny all apache .htaccess or .htpasswd files
location ~ /.ht
deny all;

Replace with your domain where ever applicable if your using vim then you can use the below code


Make simlink to sites-enabled

ln -sf /etc/nginx/sites-available/ /etc/nginx/sites-enabled/

Step 5: Install php-fpm

yum install php php-fpm php-gd php-mysql php-mbstring php-xml php-mcrypt

Add a user for your site and goto /etc/php-fpm.d/, open www.conf and add the change the user to yourusername

; RPM: apache Choosed to be able to access some dir as httpd
user = leo
; RPM: Keep a group allowed to write in log dir.
group = leo

Now restart Nginx and php-fpm

service nginx restart
service php-fpm restart

php-fpm uses a lot of memory

max children-- This is the maximum number of child processes, this should be kept low and should be the same as max spare servers.
The more processes the more memory used, hence this should be low

max requests : This should neither be too low or too high as too low means that the process needs to be recreated very often thus cpu usage and too high means that memory used will be more as to handle more connections memory is used.

You should also read a speed up php with opcode cache

For optimization please check




Creative Commons License
All posts Content by Leonard Gonsalves is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at
Permissions beyond the scope of this license may be available at