Lompat ke konten Lompat ke sidebar Lompat ke footer

Install NginX dan PHP di centos 6

Assalamu'alaikum Wr. Wb.
Balik lagi dengan ane .. gmne kbarnya ? mudah-mudahan pada sehat semua ya .. Aminn

kali ini ane akan memberikan tutorial install nginx dan php di centos 6
okelahh langsung aje.


pertama ente instal centOS dulu ye .. sterah ente mao di VirtualBox apa langsung di pc/laptop ente,
kalo udah di instal langsung aje ikuti tutor di bawah

kalo udah di instal centOSnya buka terminal di Application>system tools>terminal.

setelah terbuka ketik command dibawah (jika ente melewatkan ini ente tidak bisa melanjutkan ke proses instalan nginx) :


32-bit:
sudo rpm -ivh http://mirror.yandex.ru/epel/6/i386/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

64-bit:
sudo rpm -ivh http://mirror.yandex.ru/epel/6/x86_64/epel-release-6-8.noarch.rpm
sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Buat file /etc/yum.repos.d/nginx.repo dan paste script di bawah :
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

install nginx, php-fpm :
yum install nginx php php-fpm php-common

atau :
yum install nginx
yum install php-fpm

Install aplikasi pendukung :
yum install spawn-fcgi 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 module php :
yum --enablerepo=remi install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

setelah di install jalankan :
service nginx start
service php-fpm start

jadikan otomatis start :
chkconfig nginx on
chkconfig php-fpm on

install nano untuk mengedit file :
yum install nano

Buat script bernama php_cgi ,pastekan script di bawah ke nano /etc/init.d/php_cgi :
#!/bin/bash

#
# php-cgi – php-fastcgi swaping via spawn-fcgi
#
# chkconfig: – 85 15
# description: Run php-cgi as app server
# processname: php-cgi
# config: /etc/sysconfig/phpfastcgi (defaults RH style)
# pidfile: /var/run/php_cgi.pid
# Note: See how to use this script :
# http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
# Source function library.
/etc/rc.d/init.d/functions

# Source networking configuration.
/etc/sysconfig/network

# Check that networking is up.
[ “$NETWORKING” = “no” ] && exit 0

spawnfcgi=”/usr/bin/spawn-fcgi”
php_cgi=”/usr/bin/php-cgi”
prog=$(basename $php_cgi)
server_ip=127.0.0.1
server_port=9000
server_user=nginx
server_group=nginx
server_childs=5
pidfile=”/var/run/php_cgi.pid”

# do not edit, put changes in /etc/sysconfig/phpfastcgi
[ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi

start() {
[ -x $php_cgi ] || exit 1
[ -x $spawnfcgi ] || exit 2
echo -n $”Starting $prog: “
#daemon
$spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P
${pidfile} -C ${server_childs} -f ${php_cgi}
retval=$?
echo
return $retval
}

stop() {
echo -n $”Stopping $prog: “
killproc -p ${pidfile} $prog -QUIT
retval=$?
echo
[ -f ${pidfile} ] && /bin/rm -f ${pidfile}
return $retval
}

restart(){
stop
sleep 2
start
}

rh_status(){
status -p ${pidfile} $prog
}

case “$1” in
start)
start;;
stop)
stop;;
restart)
restart;;
status)
rh_status;;
*)
echo $”Usage: $0 {start|stop|restart|status}”
exit 3
 
jalankan command :
chmod +xw /etc/init.d/php_cgi

Konfigurasi file /etc/nginx/conf.d/default.conf :
server {
    listen     80;
    server_name  localhost;
    root         /usr/share/nginx/html;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

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

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;

        #fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    

}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}
 
Buat file dan isi script berikut di /usr/share/nginx/html/testphp.php
<?php
phpinfo();
?>

cek apakah nginx sudah terinstal atu belum dibrowser anda, ketikan ip server aand untuk melihat nginx :



Buka file /etc/php.in:
nano /etc/php.ini

Gantilah baris :
cgi_fix_path_info=1
dengan
cgi_fix_path_info=0

save dengan menekan ctrl+x ,y ,enter

Konfigurasi PHP-FPM
nano /etc/php-fpm.d/www.conf

Gantil tulisan apache dengan nginx yang yang di user dan group (gunakan CTRL+W untuk mempercepat pencarian):
[...]
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
[...]

save dengan ctrl+x ,y ,enter

buat folder untuk virtual host :
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled

Tambahkan file di /etc/nginx/nginx.conf setelah file "include /etc/nginx/conf.d/*.conf" :
include /etc/nginx/sites-enabled/*;

Tambah virtual host di /etc/nginx/sites-available/testphp.info :
server {
    listen    80;
    server_name localhost;
    root        /usr/share/nginx/html;

    location / {
        index index.html index.htm index.php;
    }

    location ~ \.php$ {
        include         /etc/nginx/fastcgi_params;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

        include         fastcgi_params;

    }
}


simpan ctrl+x ,y ,enter

buat symlink untuk virtual host dan restart nginx
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/testphp.info

service nginx restart

Buat virtual host di /etc/host :
127.0.0.1 localhost testphp.info

jangan lupa disimpan

Restart nginx dan PHP :
service nginx restart
service phpfpm restart

Buka browser ente and ketik ip server/testphp.php, maka tampilannye akan seperti:



Okelah segiu aja dulu yee .
kalo ada masalah jangan sungkan bertanya ..

TERIMAKASIH .

Wassalamu'alaikum Wr. Wb.
Dionannd
Dionannd Designer/Programmer

Posting Komentar untuk "Install NginX dan PHP di centos 6"

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel