Setting up PHP in NGINX with FastCGI

As we mentioned is an earlier chapter, linking modules into a multi-threaded HTTP server requires that the code in the module be thread safe. Nginx works around this by utilizing the fastcgi protocol to interact with interpreters rather than linking them directly into the process. This does not have quite the performance of the more native approach, but you can limit what content runs through the processor.

How to do it…

Configuring on Ubuntu 14.04:

  1. Install the PHP FastCGI wrapper:
    sudo apt-get install php5-fpm
    
  2. Modify php's configuration file to disable cgi.fix_pathinfo, this setting opens the door to security vulnerabilities by allowing PHP to guess at what your request was intending to request:
    sed 's/.*cgi.fix_pathinfo=.*/cgi.fix_pathinfo=0/g' ...

Get Linux Networking Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.