Posted by: Mangesh_Linux_Administrator | January 20, 2011

Install Nginx PHP5 FastCGI Webserver


Install NginX  Php5 FastCGI webserver

Nginx (engine x) is an HTTP(S) server, reverse proxy and IMAP/POP3 proxy server written by Igor Sysoev. It is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

Configure yum  repo for needful packages

# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/$(uname -m)/epel-release-5-3.noarch.rpm

Install Nginx

# yum install nginx

Configuration files of nginx

  • Default config file: /etc/nginx/nginx.conf
  • Default SSL config file: /etc/nginx/conf.d/ssl.conf
  • Default virtual hosting config file: /etc/nginx/conf.d/virtual.conf
  • Default documentroot: /usr/share/nginx/html

Configure PHP As FastCGI

# yum install php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql

Install spawn-fcgi simple program for spawning FastCGI processes

# yum install spawn-fcgi
Next, download spawn-fcgi init.d shell script:

# wget http://bash.cyberciti.biz/dl/419.sh.zip
# unzip 419.sh.zip
# mv 419.sh /etc/init.d/php_cgi
# chmod +x /etc/init.d/php_cgi

Start php app server

# /etc/init.d/php_cgi start
# netstat -tulpn | grep :9000

By default php server listens on 127.0.0.1:9000 port. Finally, update /etc/nginx/nginx.conf as follows:

# vi /etc/nginx/nginx.conf

Modify / append as follows:

——————————————————–

location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

——————————————————————–

Save and close the file. Restart nginx:

# service nginx restart

Create /usr/share/nginx/html/test.php as follows:

——————————-

<?php

     phpinfo();
?>
-------------------------
Advertisements

Responses

  1. Magnificent beat ! I would like to apprentice even as you amend your website, how could
    i subscribe for a blog site? The account helped me a appropriate deal.
    I were a little bit acquainted of this your broadcast offered vibrant transparent idea


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: