Centos wordpress php-fpm + nginx + apc

If you tired of having same old apache, and want something more fast and reliable, you can install nginx + php-fpm.

Firstly you need to install new repo, to have ability to add those packages. And php-fpm works out of the box (without need to patch PHP) with version PHP 5.3. Official repository does not have this version yet.

wget -q -O - http://www.atomicorp.com/installers/atomic.sh | sh
yum install nginx php-fpm php-pecl-apc

When you have more virtual hosts than one, and you want to have more convenient way to manage them, well to turn them on and off if being more precisely.
You can create two config directories. One directory “sites-available” to gave all nginx virtual host configs, and “sites-enabled”, which will be included in main nginx config file, and all symbolic links would be kept inside this direcotory pointing to real config files.

so,

mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled

then edit /etc/nginx/nginx.conf file:

vim /etc/nginx/nginx.conf

after “include /etc/nginx/conf.d/*.conf”
insert line “include /etc/nginx/sites-enabled/*.conf”

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*.conf;
}

and save it.

loginroot.com nginx vhost example (basic configuration just to make it work):

vim /etc/nginx/sites-enabled/loginroot.com
server {
    listen       *:80;
    server_name  loginroot.com  www.loginroot.com;

    error_log  /var/log/nginx/loginroot.com-error.log;
    access_log /var/log/nginx/loginroot.com-access.log main;

    root   /home/sites/loginroot.com;


    location / {
        index  index.php index.html index.htm;
    }

    # force to use loginroot.com witout 'www'
    if ($host = 'www.loginroot.com' ) {
       rewrite  ^/(.*)$  http://loginroot.com/$1  permanent;
    }

   # 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/loginroot.com;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /home/sites/loginroot.com$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

    # deny all apache .htaccess or .htpasswd files
    location ~ /\.ht
    {
        deny all;
    }
}

php-fpm default configuration should be alringht.
Well you may want to change to lines where are user and group, from apache to nginx.

vim /etc/php-fpm.d/www.conf
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx

also you may want to make nginx the owner of that directory.

chown -R nginx:nginx /home/sites/loginroot.com

make symbolic link to make vhost working.

ln -s /etc/nginx/sites-available/loginroot.com /etc/nginx/sites-enabled

Start both services, and you’re set :)

/etc/init.d/php-fpm start
/etc/init.d/nginx start

2 thoughts on “Centos wordpress php-fpm + nginx + apc

  1. I think you got couple of paths wrong

    vim /etc/nginx/sites-enabled/loginroot.com

    shouldn’t this be

    vim /etc/nginx/sites-available/loginroot.com ?

    1. all config files I keep in sites-available, but nginx takes from sites-enabled directory.
      Sites that I want to be enabled and working, I just create symlink to file existing in sites-available directory.
      So if site is enabled – “vim /etc/nginx/sites-enabled/loginroot.com” should work, because it is symlink to “/etc/nginx/sites-available/loginroot.com”.
      Anyway You would edit the same file.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.