Installing NGINX and PHP-FPM on CentOS

20 Dec

We wanted to run some benchmarks comparing Apache/Mod_PHP and NGINX/PHP-FPM. Here are the steps I followed to install NGINX/PHP-FPM on our CentOS servers.

Configure Additional Yum Repositories

  • If you haven’t already added the EPEL and REMI repositories execute the following steps:
  1. Install the EPEL YUM Repository
  2. Install the REMI Yum Repository
  3. For more information see EPEL and REMI

NGINX installation

  1. yum install nginx

Install PHP packages

  1. Follow the steps specific to PHP installation at

Install PHP-FPM

  1. yum –enablerepo=remi install php-fpm
  1. To upgrade to the latest PHP/PHP-FPM packages: yum –enablerepo=remi upgrade

Enable the NGINX and PHP-FPM as CentOS services

  1. chkconfig nginx on
  2. chkconfig php-fpm on

NGINX and PHP configuration changes

nginx.conf changes

  • Add the following fastcgi settings in the location for php section in the nginx.conf file:


            # pass the PHP scripts to FastCGI server listening on
            location ~ \.php$ {
                root /usr/share/nginx/html;
                fastcgi_index  index.php;
                #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                fastcgi_param  SCRIPT_FILENAME  $fastcgi_script_name;
                fastcgi_intercept_errors off;
                include        fastcgi_params;

php.ini changes

  • Set log_error On in php.ini to enable php error logging.
    • The error output will be written to /var/log/httpd/error_log

NGINX Troubleshooting

  • If you see an error in the log file related to eventfd() and you are unable to access a web page, you will
    have to build NGINX from source
    • Install pre-reqs
      • yum install libaio libaio-devel
    • Download latest version of PCRE from and extract under /opt/pcre
    • Download latest version of NGINX from under /opt/nginx
    • Build nginx
      • cd /opt/nginx/nginx-XX
      • ./configure –with-pcre=/opt/pcre/pcre-XX
      • make
      • make install
  • The nginx scripts and config files are installed under /usr/local/nginx
  • If you already have installed NGINX using the yum method you can update /etc/init.d/nginx to point to the nginx executable
    and configuration under /usr/local/nginx

Important file2 and directory locations after installation


  • /etc/nginx/nginx.conf (NGINX Configuration file)
  • /usr/share/nginx/html (NGINX Document Root)
  • /var/log/nginx/* (NGINX Log Files)


  • /etc/php-fpm.conf
  • /etc/php-fpm.d/www.conf


  • /etc/php.ini (Php INI file)

Start/Stop Scripts

  1. NGINX
    1. service nginx stop
    2. service nginx start
    3. service nginx restart
  2. PHP-FPM (Used with NGINX)
    1. service php-fpm stop
    2. service php-fpm start
    3. service php-fpm restart


  1. PHP-FPM configuration
  2. PHP-FPM vs FastCGI comparison

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: