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: 3
Members Members: 0
Total Total: 3

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
119 posts
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 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:


## ABSOLUTE path to the PHP binary

## tcp-port to bind on

## IP to bind on

## number of PHP children to spawn

## number of request before php-process will be restarted

# allowed environment variables sperated by spaces

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

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_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.


 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