Wednesday, 11 May 2011

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$(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
# unzip
# mv /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 port. Finally, update /etc/nginx/nginx.conf as follows:

# vi /etc/nginx/nginx.conf

Modify / append as follows:


location ~ \.php$ {
root html;
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:



No comments:

Post a Comment