Install and Config NGINX with PHP 5.6 on Centos 6.x

NGINX adalah

a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

mungkin detailnya bisa dibaca sendiri aj ya..hehehe…sebenernya sih sama konsepnya ama apache, yah..gak ada salahnya khan ya kita coba oprek make ini. Baik kita mulai ya..

Add repository dulu

Install NGINX

#yum install nginx
#service nginx start
#chkconfig nginx on

Config NGINX.

Ada 2 file yang ‘wajib’ kita config yaitu default.conf dan nginx.conf.

a). Config default.conf

#vi /etc/nginx/conf.d/default.conf
then replace and add with this

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        listen 443 ssl;
        root /var/www;
        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;
        server_name _;
        ssl_certificate /etc/nginx/ssl.crt;
        ssl_certificate_key  /etc/nginx/ssl.key;
        location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
        location ~ \.php$ {
        root           /usr/share/nginx/html;
        try_files $uri =404;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
location ~ /\.ht {
        deny  all;
b). Config nginx.conf
#vi /etc/nginx/nginx.conf
then replace and add with this
user  nginx;
worker_processes  1;
error_log  /var/log/nginx/error.log warn;
pid        /var/run/;
events {
worker_connections  1024;
http {
include       /etc/nginx/mime.types;
default_type  application/octet-stream;
log_format  main  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
 ‘$status $body_bytes_sent “$http_referer” ‘
 ‘”$http_user_agent” “$http_x_forwarded_for”‘;
access_log  /var/log/nginx/access.log  main;
sendfile        on;
#tcp_nopush     on;
keepalive_timeout  65;
#gzip  on;
include /etc/nginx/conf.d/*.conf;
or with tunning nginx.conf

user  nginx;
worker_processes  4;
events {
    worker_connections   65536;
    use epoll;
    multi_accept on;
http {
    keepalive_timeout 65;
    keepalive_requests 100000;
    sendfile         on;
    tcp_nopush       on;
    tcp_nodelay      on;
    client_body_buffer_size    128k;
    client_max_body_size       10m;
    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;
    output_buffers   1 32k;
    postpone_output  1460;
    client_header_timeout  3m;
    client_body_timeout    3m;
    send_timeout           3m;
    open_file_cache max=1000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 5;
    open_file_cache_errors off;
    gzip on;
    gzip_min_length  1000;
    gzip_buffers     4 4k;
    gzip_types       application/x-javascript text/css application/javascript text/javascript text/plain text/xml application/json application/ application/x-font-opentype application/x-font-truetype application/x-font-ttf application/xml font/eot font/opentype font/otf image/svg+xml image/;
    gzip_disable “MSIE [1-6]\.”;
    # [ debug | info | notice | warn | error | crit | alert | emerg ]
    error_log  /var/log/nginx.error_log  warn;
    log_format main      ‘$remote_addr – $remote_user [$time_local]  ‘
      ‘”$request” $status $bytes_sent ‘
      ‘”$http_referer” “$http_user_agent” ‘
    log_format download  ‘$remote_addr – $remote_user [$time_local]  ‘
      ‘”$request” $status $bytes_sent ‘
      ‘”$http_referer” “$http_user_agent” ‘
  ‘”$http_range” “$sent_http_content_range”‘;
    map $status $loggable {
        ~^[23]  0;
        default 1;
include       /etc/nginx/mime.types;
include /etc/nginx/conf.d/*.conf;
    server {
        root         /usr/share/nginx/html;
        access_log   /var/log/nginx.access_log  main;
        location / {
            proxy_redirect     off;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP        $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_connect_timeout      90;
            proxy_send_timeout         90;
            proxy_read_timeout         90;
            proxy_buffer_size          4k;
            proxy_buffers              4 32k;
            proxy_busy_buffers_size    64k;
            proxy_temp_file_write_size 64k;
#proxy_cache_path /var/cache/nginx 1:2 keys_zone=my-cache:8m max_size=1000m inactive=600m;
            proxy_temp_path             /var/cache/nginx/proxy_temp 1 2;
#proxy_cache cache;
proxy_cache_key $host$request_uri$cookie_NO_CACHE;
proxy_ignore_headers Cache-Control Expires;
proxy_pass_header Set-Cookie;
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 1m;
        location ~* .(woff|eot|ttf|svg|mp4|webm|jpg|jpeg|png|gif|ico|css|js)$ {
            expires 365d;
install php

#yum install php56w php56w-common php56w-fpm php56w-mbstring php56w-mcrypt php56w-pear php56w-mysql php56w-gd
#chkconfig php-fpm on
#service php-fpm start
config php
#vi /etc/php-fpm.d/www.conf
add and config with this

user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock
listen.user = nginx = nginx
Sekarang coba jalankan nginx..eitsss jangan lupa bikin phpinfo.php ya..tinggah ditaruh aj di folder
selamat mencoba 🙂

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s