NginX

PHP FPM

PHP is not integrated into NginX but it runs as a standalone process. PHP-FPM controlls that process.

 

Ubuntu 12.04

#apt-get install php5-common php5-cli php5-fpm

#php5 -v

PHP 5.3.10-1ubuntu3.16 with Suhosin-Patch (cli) (built: Feb 13 2015 20:15:22)

 

If you want upgrade to PHP5.5 do the following:

  1. a) # apt-get install python-software-properties (ako već nije instaliran pri upgradeu nginX-a)
  2.  b) # add-apt-repository ppa:ondrej/php5
  3.  c) # apt-get update
  4.  d) # apt-get dist-upgrade
  5.  e) sada # php --version daje

PHP 5.5.12-2+deb.sury.org~precise+1 (cli) (built: May 12 2014 13:46:35)

Copyright (c) 1997-2014 The PHP Group

Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

 

 

 

 

PHP-FPM (FastCGI Process Manager)

$sudo service php5-fpm start

$sudo service php5-fpm restart

$sudo service php5-fpm stop

 

By default PHP-FPM is using TCP connection 127.0.0.1:9000 to NginX or other processes.

To change this edit /etc/php5/fpm/pool.d/www.conf file

Instead of

          listen = 127.0.0.1:9000

put

          listen = /var/run/php5-fpm.sock

 

Sockets are faster but sockets are only reachable from programs that are running on the same server.

 

 

 

NGINX VIRTUAL HOST CONFIG

server {
    
  ############### General Settings ####################
    listen   80;
    server_name  www.adsuu.loc;
    root    "/homemiko/com_adsuu/www/pub/";
    index  index.php index.html;
    charset utf-8;
    autoindex on;
    error_log "/homemiko/com_adsuu/logs/www_adsuu_com_error.log";
   #access_log "/homemiko/com_adsuu/logs/www_adsuu_com_access.log";

  ############### deny access to apache .htaccess files ####################
  location ~ /\.htaccess {
    deny all;
   }
    
  ################# PHP ###################
    location ~ \.php$ {
      try_files $uri =404; #This line closes a big security hole
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      #fastcgi_pass unix:/var/run/php5-fpm.sock;
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fastcgi_params;
  }


}

 

Errors

1. When we are using php-fpm socket error 502 Bad gateway can occur

log file ---> connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied)

SOLUTION:

a) uncoment lines in /etc/php5/fpm/pool.d/www.conf

listen.owner = www-data
listen.group = www-data
listen.mode = 0660

b) check if the user is www-data in /etc/nginx/nginx.conf

user www-data;

c) restart nginx and php-fpm

#service nginx restart

#service php5-fpm restart