Setup Nginx, php5 (php5-fpm), mysql server dan phpmyadmin di debian

Suatu waktu berkesempatan mencoba Nginx (engine-X), yang konon katanya high-performance web server, ringan, dan cepat :).. bisa dibaca di http://wiki.nginx.org

Nginx is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. Igor Sysoev started development of Nginx in 2002, with the first public release in 2004. Nginx now hosts nearly 11.28% (43M) of all domains worldwide. Netcraft predicts that current trends will soon have Nginx surpassing Microsoft IIS as the second most popular web server.

Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.

Nginx is one of a handful of servers written to address the C10K problem. Unlike traditional servers, Nginx doesn’t rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. This architecture uses small, but more importantly, predictable amounts of memory under load.
Even if you don’t expect to handle thousands of simultaneous requests, you can still benefit from Nginx’s high-performance and small memory footprint. Nginx scales in all directions: from the smallest VPS all the way up to clusters of servers.

Nginx powers several high-visibility sites, such as WordPress, Hulu, Github, Ohloh, SourceForge, WhitePages and TorrentReactor.

Karena memang dipakai buat php programming, dan mysql server buat databasenya, alangkah baiknya jika dicatat agar penulis sendiri tidak lupa 🙂 dan mudah-mudahan bermanfaat bagi yang lain 🙂
Saya menggunakan debian linux 64 bit, untuk sistem sejenis (ubuntu, mint dll) saya rasa tinggal disesuaikan sendiri…

  • Installasi nginx, php5-fpm
    Sayang sekali, repository default debian belum menyertakan php5-fpm, jadi penulis menambahkan repository “non formal” http://packages.dotdeb.org/ ke sources.list, lalu jalankan update dan install 🙂

    $echo deb http://packages.dotdeb.org/ stable all | sudo tee -a /etc/apt/sources.list

    tambahkan keyring,

    $wget http://www.dotdeb.org/dotdeb.gpg
    $cat dotdeb.gpg | sudo apt-key add -
    $sudo apt-get update

    Kemudian install nginx web server dan php5-fpm, beserta paket lain yang diperlukan
    $sudo apt-get install php5-cli php5-suhosin php5-fpm php5-cgi php5-mysql nginx mysql-server phpmyadmin

    Default instalasi nginx di debian tidak membuat dan menggunakan /var/www sebagai root dokumen-nya untuk web, tetapi default bawaannya menggunakan direktori /usr/share/nginx/www.

  • Konfigurasi Nginx

  • Agar bisa diakses localhost, buka dan edit file /etc/nginx/sites-available/default

    $gksudo gedit /etc/nginx/sites-available/default

    dan rubah root direktorinya, menjadi

    server {
    #listen 80; ## listen for ipv4; this line is default and implied
    #listen [::]:80 default ipv6only=on; ## listen for ipv6

    root /var/www;
    index index.html index.php index.htm;
    ...........

    Kemudian agar nginx bisa memproses php script menggunakan php-fpm tadi, tambahkan di /etc/nginx/sites-available/default, sehingga menjadi


    ............
    location ~ .php$ {
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    fastcgi_pass backend;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_param REQUEST_METHOD $request_method;
    fastcgi_param CONTENT_TYPE $content_type;
    fastcgi_param CONTENT_LENGTH $content_length;
    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    }

    ## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
    deny all;
    }
    }
    upstream backend {
    server 127.0.0.1:9000;
    }
    ......

    Kemudian kita test, dengan membuat file index.php di bawah direktori /var/www, dengan isi :


    dan coba cek apakah nginx bisa memproses php script tersebut. Kalau sukses, dan tidak ada masalah.. seperti scrinsut di bawah

    Kemudian untuk menambahkan phpmyadmin agar bisa diakses, tambahkan baris berikut di /etc/nginx/sites-available/default,

    location /phpmyadmin {
    root /usr/share/;
    index index.php index.html index.htm;
    location ~ ^/phpmyadmin/(.+\.php)$ {
    try_files $uri =404;
    root /usr/share/;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    include /etc/nginx/fastcgi_params;
    }
    location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
    root /usr/share/;
    }
    }
    location /phpMyAdmin {
    rewrite ^/* /phpmyadmin last;
    }

    yang nantinya agar bisa diakses dengan alamat http://localhost/phpmyadmin.. ini scrinsut punya penulis

    Dan tinggal dikembangkan 🙂

    Advertisements
    Comments
    One Response to “Setup Nginx, php5 (php5-fpm), mysql server dan phpmyadmin di debian”
    1. Bismillahirrahmanirrahim.

      Dokumentator senior memang beda. Terima kasih, Kang.

    Leave a Reply

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

    WordPress.com Logo

    You are commenting using your WordPress.com 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 )

    Google+ photo

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

    Connecting to %s

    %d bloggers like this: