ilmu-linux.com

Network & Linux opensource

 

install nginx PHP Centos 5.6

 

Download Repo nginx di alamat http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm

 

# install Repo nginx

rpm-ivh nginx-release-centos-5-0.el5.ngx.noarch.rpm

# install nginx

yum install nginx

 

#Konfigurasi nginx

--- Install nginx ---

 

Download Repo nginx di alamat http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm

 

# install Repo nginx

rpm-ivh nginx-release-centos-5-0.el5.ngx.noarch.rpm

# install nginx

yum install nginx

 

#Konfigurasi nginx

edit file /etc/nginx/conf.d/default.conf

untuk merubah DocumentRoot

kasih pagar    root   /usr/share/nginx/html;

tambahkan    root   /var/www/html;

tambahkan pula index.php

 location / {
    #  root   /usr/share/nginx/html;
        root   /var/www/html;
        index  index.html index.htm index.php;
    }

 

--- Install php (Compile) ---

tar -jxvf php-5.2.17.tar.bz2

cd php-5.2.17

./configure --prefix=/usr/local/php5 --with-openssl --with-zlib --with-bz2 --enable-calendar --with-curl --enable-exif --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --enable-mbstring --with-mcrypt --with-mysql --enable-sockets --enable-zip --enable-zend-multibyte --enable-pdo --with-snmp --enable-fastcgi --enable-force-cgi-redirect

make

make install

 

# Konfigurasi php.ini

cp /usr/local/src/php-5.2.17/php.ini-recommended /usr/local/php5/lib/php.ini

 

# Konfigurasi nginx agar terkoneksi dengan php fastcgi

Edit file /etc/nginx/conf.d/default.conf

cari tulisan  location ~ \.php$

beri tanda pagar  fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

tambahkan menjadi fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;

(/var/www/html adalah DocumentRoot)

 

 location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
    #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
        include        fastcgi_params;
    }

 

 

Bikin init php fast cgi

copy skrip init di bawah ini ke file /etc/init.d/php-fcgi

ubah

HPFCGI="/usr/bin/php-cgi" menjadi HPFCGI="/usr/local/php5/bin/php-cgi"

 

#!/bin/bash
#
# Startup script for the PHP FastCGI server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: php
# config: /etc/php.ini
 
# Source function library.
. /etc/rc.d/init.d/functions
 
PHPFCGI="/usr/bin/php-cgi"
FCGIPORT="9000"
FCGIADDR="127.0.0.1"
FCGI_WEB_SERVER_ADDRS="127.0.0.1"
PHP_FCGI_CHILDREN=5
PHP_FCGI_MAX_REQUESTS=1000
ALLOWED_ENV="PATH USER"
PHPUSER=php
PIDFILE=/var/run/phpfcgi.pid
 
if [ -z "$PHP_FCGI_CHILDREN" ]; then
  PHP_FCGI_CHILDREN=5
fi
 
ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
 
case "$1" in
  start)
        PHPFCGI_START=$"Starting ${NAME} service: "
        echo -n $PHPFCGI_START
 
        # check for $PHPUSER, create if non-existent
        if [ -z "`id -u $PHPUSER 2> /dev/null`" ]; then
            useradd -s /sbin/nologin $PHPUSER
        fi
 
        # clean environment
        E=
        for i in $ALLOWED_ENV; do E="$E $i=${!i}"; done
        daemon --user $PHPUSER --pidfile $PIDFILE "env - $E $PHPFCGI -q -b $FCGIADDR:$FCGIPORT &> /dev/null &"
 
        pid=`pidof php-cgi`
        if [ -n "$pid" ]; then
            echo $pid > $PIDFILE
            success $PHPFCGI_START
        else
            failure $PHPFCGI_START
        fi
        echo
        ;;
  stop)
        echo -n "Stopping php-fcgi: "
        killproc -p $PIDFILE phpfcgi
        echo
        ;;
  status)
        status phpfcgi
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|status|restart}"
        exit 1
esac
 
exit 0

 

restart  nginx    /etc/init.d/nginx restart

restart php-fcgi  /etc/init.d/php-fcgi restart

 

Buat file info.php di /var/www/html/

<?php

phpinfo();

?>

 

lihat hasil nya di browser http://localhost/info.php

 

kalo muncul informasi php berarti nginx sudah terkoneksi dengan php

 

terima kasih

 

 

 

 

 

Leave a reply

Feel free to share your thoughts about this entry.

Nickname
Email
Website
Confirmation image
Confirmation code
Comment