Membership Membership:
Latest New User Latest: vpros
Past 24 Hours Past 24 Hours: 0
Prev. 24 Hours Prev. 24 Hours: 0
User Count Overall: 137

People Online People Online:
Visitors Visitors: 58
Members Members: 0
Total Total: 58

NakedMCSE Computer Tech Support Forums

So you have passed all of the exams and you are now out in the real world of windows servers, linux servers and freebsd servers faced with a tech support problem you have never seen before...

Find free online tech support in the forums below, respecting that advice is free, but work beyond advice is not...

The General forum is provided for off topic discussion.

You need a user account to post - please Register or Login.

Online Tech Support Forums
 
  Forum  Open Source Tec...  NGINX Server  PHP FastCGI setup with Nginx
Previous Previous
 
Next Next
New Post 12/24/2009 12:07 PM
Informative
  Walker
119 posts
www.lairdscomputer.com
10th Level Poster


PHP FastCGI setup with Nginx 
Modified By Walker  on 12/24/2009 1:11:07 PM)

Prerequisite is that nginx is installed.

First download the source code for the version of PHP you wish to install and then install it by extracting it to a directory and running the following commands:

./configure --prefix=/usr/local/phpfcgi --enable-fastcgi
make
make install

This will install the version of PHP you chose to /usr/local/phpfcgi.  You will need to edit the file /usr/local/phpfcgi/etc/php.ini to contain your php.ini settings.  Note well that the php.ini must contain cgi.fix_pathinfo=1.

Then you need to install a wrapper script to run the PHP fastcgi server.  One is attached to this post.  If you chose to use it, you will need to edit the variables below:

#!/bin/bash

## ABSOLUTE path to the PHP binary
PHPFCGI="/usr/local/phpfcgi/bin/php-cgi"

## tcp-port to bind on
FCGIPORT="8888"

## IP to bind on
FCGIADDR="127.0.0.1"
FCGI_WEB_SERVER_ADDRS="127.0.0.1"

## number of PHP children to spawn
PHP_FCGI_CHILDREN=5

## number of request before php-process will be restarted
PHP_FCGI_MAX_REQUESTS=1000

# allowed environment variables sperated by spaces
ALLOWED_ENV="PATH USER"

## if this script is run as root switch to the following user
USERID=wwwdata

Once this is done you can run the script at startup to start the PHP fastcgi server processes.

Now you need to modify the nginx configuration file to send PHP requests to the PHP fastcgi server processes:

        location ~ .*\.php$ {
            root  /var/wwwroot/;
            include fastcgi_params;
            fastcgi_pass   127.0.0.1:8888;
            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /var/wwwroot$fastcgi_script_name;
            }

You would change the /var/wwwroot to the root of your webserver directory.

Finally you need to modify the fastcgi_params file as follows:

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

Restart Nginx to pick up the changes and you will now be able to use .php files.

Walker
www.lairdscomputer.com

 
 Login to download attachment
Previous Previous
 
Next Next
  Forum  Open Source Tec...  NGINX Server  PHP FastCGI setup with Nginx
Send me One Million FREE Guaranteed Visitors