Sunday, January 9, 2011

How to Install fastcgi and Nginx on Centos

Install PHP & depends:

yum install gcc pcre-devel openssl-devel 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


Download & install spawn-fcgi

cd /usr/local/src
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -xzvf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure
make & make install


add user nginx

useradd nginx


Create file fastcgi in /etc/init.d/ directory and put

#!/bin/bash
PHP_SCRIPT=/usr/local/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php
RETVAL=$?
;;
restart)
killall -9 php
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL



change mode

chmod 755 fastcgi


Create file /usr/local/bin/php-fastcgi

#!/bin/sh
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -f /usr/bin/php-cgi


change mode

chmod 755 /usr/local/bin/php-fastcgi


Download and install nginx

cd /usr/local/src
wget http://sysoev.ru/nginx/nginx-0.8.54.tar.gz
tar -xzvf nginx-0.8.54.tar.gz
cd nginx-0.8.54

./configure --prefix=/usr --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access_log --error-log-path=/var/log/nginx/error_log --pid-path=/var/run/nginx.pid --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --with-md5-asm --with-md5=/usr/include --with-sha1-asm --with-sha1=/usr/include --with-http_realip_module --with-http_ssl_module --with-http_perl_module --with-http_stub_status_module

make & make install




Create configuration file for nginx /etc/nginx/nginx.conf

worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 10m;
sendfile on;
charset utf-8;
gzip on;
gzip_types text/plain application/xml text/javascript;
gzip_min_length 1000;

keepalive_timeout 65;



server {
listen 80;
server_name www.3nky.com;
server_tokens off;
root /home/3nky/public;
index index.php index.html index.htm;

access_log /var/log/nginx/3nky.com-access_log;
error_log /var/log/nginx/3nky.com-error_log;

#location / {
# try_files $uri /index.php;
#}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}


location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

}
}


No comments: