NGINX - performance HTTP server Support Forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the Unofficial (YET) support forums for NGINX, a performance HTTP server.

Pages: [1]   Go Down

Author Topic: Nginx With PHP As FastCGI Howto  (Read 775 times)

0 Members and 1 Guest are viewing this topic.

katmai

  • Administrator
  • Jr. Member
  • *****
  • Karma: 0
  • Offline Offline
  • Posts: 57
    • View Profile
Nginx With PHP As FastCGI Howto
« on: November 30, 2007, 02:56:56 PM »
Nginx supports FastCGI technology to work with many external tools and servers. PHP itself can be runned as FastCGI application and can process FastCGI requests from nginx.

So, first of all we need to install PHP with fastcgi support and run it on some local tcp port. Installation process can go different ways, but I will describe here how to compile PHP from sources because it is generic way. To get fastcgi-enabled version of PHP interpreter, you may use following commands:
Code: [Select]
# ./configure --prefix=/opt/php --enable-fastcgi
...
# make
...
# make install
...
#Code: [Select]
#!/bin/bash

## ABSOLUTE path to the PHP binary
PHPFCGI="/opt/php/bin/php"

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

## IP to bind on
FCGIADDR="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="ORACLE_HOME PATH USER"

## if this script is run as root switch to the following user
USERID=www-data

################## no config below this line

if test x$PHP_FCGI_CHILDREN = x; then
  PHP_FCGI_CHILDREN=5
fi

ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN"
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS"
ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS"

if test x$UID = x0; then
  EX="/bin/su -m -c \"$PHPFCGI -q -b $FCGIADDR:$FCGIPORT\" $USERID"
else
  EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT"
fi

echo $EX

# copy the allowed environment variables
E=

for i in $ALLOWED_ENV; do
  E="$E $i=${!i}"
done

# clean environment and set up a new one
nohup env - $E sh -c "$EX" &> /dev/null &
here):
Code: [Select]
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:8888
#
location ~ .php$ {
  fastcgi_pass   127.0.0.1:8888;
  fastcgi_index  index.php;

  fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;
  fastcgi_param  QUERY_STRING     $query_string;
  fastcgi_param  REQUEST_METHOD   $request_method;
  fastcgi_param  CONTENT_TYPE     $content_type;
  fastcgi_param  CONTENT_LENGTH   $content_length;
}

That is all! Now you can use your nginx to serve any PHP-enabled sites and its performance will be very close to Apache mod_php module, but you will get more memory to process more requests from your site visitors.

As always, if you have some questions or suggestions, you can post them in comments area.

Courtesy of Kovyrin
Logged

zlzqq

  • Newbie
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 16
  • Just started
    • View Profile
Re: Nginx With PHP As FastCGI Howto
« Reply #1 on: August 05, 2010, 07:31:57 AM »



Who is the one wow power leveling who feels that having a joint pain does not disrupts ones lifestyle, frankly speaking no one as wow power leveling joint pain is one such thing that can stop one from even performing the daily wow power leveling life activities. The discomfort that the joint pain provides is often world of warcraft power leveling accompanies by swelling and this can be lead to severe pain in the long run. Most wow cheap gold of the people are willing to go in for a natural remedy when it comes to joint pain as in this gold for wow case, chances of any side effect occurring are completely less. Nutrition clubbed together world of warcraft power leveling with VitaMedica's joint pain relief can help anyone get rid of even the severest of pain in a quick span of time.
Logged
Pages: [1]   Go Up
« previous next »
 

Page created in 0.041 seconds with 20 queries.