study kasus webserver dan penyelesaiannya


study kasus

Buatlab webserver untuk subdomain "x".inilab.net (195.109.14.100/26). Webserver yg anda buat nantinya akan difungsikan sebagai web blog.
NB : x disesuaikan dengan nama server anda.

penyelesaian

1. Setup IP Address
# ifconfig eth2 195.109.14.100 netmask 255.255.255.192 broadcast  195.109.14.191


2. Buat script kompilasi untuk webserver (nginx)
# pico nginx.sh
 >#!/bin/bash
   ver=1.4.3
   tar -zxvf nginx-$ver.tar.gz
   test ! -d /var/tmp/fastcgi && mkdir /var/tmp/fastcgi
   test ! -d /var/tmp/body && mkdir /var/tmp/body
   echo \"Direktori-nya sudah ada\"
   cd nginx-$ver
   ./configure --prefix=/usr/local/nginx \\
               --user=nobody --group=nobody \\
                       --http-fastcgi-temp-path=/var/tmp/fastcgi \\
                       --http-client-body-temp-path=/var/tmp/body \\
                       --with-perl=/usr/bin/perl \\
                       --with-pcre
   make
   make install
   test ! -d /usr/local/nginx/conf/vhost && mkdir /usr/local/nginx/conf/vhost
   echo \"Direktori-nya sudah ada\"
   chmod 700 /var/tmp/body
   chmod 700 /var/tmp/fastcgi
   chown -R nobody:root /var/tmp/body
   chown -R nobody:root /var/tmp/fastcgi
   cd /usr/local/src


3. Install WebServer (nginx)
    # chmod 755 nginx.sh
    # ./nginx.sh


4. Konfigurasi WebServer
   - Edit nginx.conf
   # pico /usr/local/nginx/conf/nginx.conf

 user nobody nobody;
   worker_processes 2;
   error_log          logs/error.log;
   pid                       logs/nginx.pid;
  
   events {
                use epoll;
                worker_connections 1024;
   }

   http {
                include 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\" \';
                tcp_nopush        off;
                tcp_nodelay       on;
                keepalive_timeout   15;
                server_tokens  off;
               
                include vhost/web.conf;
   }                          


- Buat file konfigurasi untuk VirtualHost   
# pico /usr/local/nginx/conf/vhost/web.conf
server {
                listen     80;
                server_name    teguh.inilab.net;
                access_log          /home/logs/teguh.inilab.log combined;
               
                root /home/web; # <---- ganti dengan nama folder yg sesuai
                index index.php index.html index.htm;
               
                location / {
                     try_files $uri $uri/ /index.php?q=$uri&$args;
                }
                error_page   500 502 503 504       /50x.html;
                location /50x.html {
                 root html;
                }
location ~ \\.php$ {
                     fastcgi_pass 127.0.0.1:9001;
                     fastcgi_index index.php;
                     include            fastcgi_params;
                }
                location ~ /.ht {
                deny all;
                }
   }


- Buat direktori untuk Data WebServer
                # mkdir /home/web
                # chown -R root:nobody /home/web

                                       
- Buat direktori untuk log VirtualHost
                # mkdir /home/logs

- Buat file index.php
                # pico /home/web/index.php

<?php
       phpinfo();
   ?>


- Edit file /usr/local/nginx/conf/fastcgi_params
   # pico /usr/local/nginx/conf/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_param   SCRIPT_FILENAME           $document_root$fastcgi_script_name;
   fastcgi_param   PATH_INFO                          $fastcgi_script_name;

   fastcgi_param   SCRIPT_NAME                 $fastcgi_script_name;
   fastcgi_param   REQUEST_URI                 $request_uri;
   fastcgi_param   DOCUMENT_URI           $document_uri;
   fastcgi_param   DOCUMENT_ROOT      $document_root;
   fastcgi_param   SERVER_PROTOCOL     $server_protocol;

   fastcgi_param   REMOTE_ADDR              $remote_addr;
   fastcgi_param   REMOTE_PORT              $remote_port;
   fastcgi_param   SERVER_ADDR               $server_addr;
   fastcgi_param   SERVER_PORT                 $server_port;
   fastcgi_param   SERVER_NAME              $server_name;

   fastcgi_param   REDIRECT_STATUS        200;


5. Start WebServer
                # /usr/local/nginx/sbin/nginx

6. Buat script kompilasi untuk PHP
               # pico php.sh
                #!/bin/bash
   ver=5.3.27
   test -d php-$ver && rm -rf
   tar -zxvf php-$ver.tar.gz
   cd php-$ver
   ./configure --prefix=/usr/local/php \\
                       --with-curl --with-mysql --with-pcre-regex \\
                       --with-gd --with-zlib --with-openssl \\
                       --with-gmp --with-jpeg-dir --with-mysql-sock \\
                       --with-config-file-path=/usr/local/php/etc \\
                       --with-fpm-user=nobody --with-fpm-group=nobody \\
                       --enable-fpm --enable-sockets --enable-mbstring \\
                       --enable-sysvmsg --enable-sysvshm --enable-sysvsem \\
                       --disable-magic-quotes --disable-ipv6
   sleep 2
   make all
   make install


7. Install PHP
# chmod 755 php.sh
# ./php.sh

8. Konfigurasi PHP
   - Edit file php.ini
        # pico /usr/local/php/etc/php.ini

[PHP]
   engine = On
   short_open_tag = Off
   asp_tags = Off
   precision = 14
   y2k_compliance = On
   output_buffering = 4096
   zlib.output_compression = Off
   implisit_flush = Off
   unserialize_callback_func =
   serialize_precision = 10
   allow_call_time_pass_reference = Off
   safe_mode = Off
   safe_mode_gid = Off
   safe_mode_include_dir = Off
   safe_mode_exec_dir = Off
   safe_mode_allow_env_vars = PHP_
   safe_mode_protected_env_vars = LD_LIBRARY_PATH
   open_basedir =
   disable_function = "system, exec, shell_exec, passthru, set_time_limit, error_log, ini_alter, dl, pfsockopen, openlog, syslog, leak, fsockopen, popen, escapeshellcmd, apache_chiled_terminate apache_gets_modiles, apache_get_version, apache_getenv, apache_note, apache_setenv, virtual, show_source"
   disable_classes =
   expose_php = Off
   max_execution_time = 300
   max_input_time = 300
   memory_limit = 128M
   error_reporting = E_ALL
   display_error = On
   display_startup_error = On
   log_errors = On
   log_errors_max_len = On
   ignore_repeated_errors = Off
   ignore_repeated_source = Off
   report_memleaks = On
   track_errors = Off
   html_errors = Off
   variables_order = "GPCS"
   request_order = "GP"
   register_globals = Off
   register_long_arrays = Off
   register_args_argv = Off
   auto_globals_jit = On
   post_max_size = 16M
   magic_quotes_qpc = Off
   magic_quotes_runtime = Off
   magic_quotes_sybase = Off
   auto_prepend_file =
   auto_append_file =
   default_mimetype = "text/html"
   doc_root =
   user_dir =
   enable_dl = Off
   cgi_force_redirect = 1
   cgi_fix_pathinfo = 0
   file_uploads = On
   upload_max_filesize = 2M
   allow_url_fopen = Off
   allow_url_include = Off
   default_socket_timeout = 60
  
   [Date]
   date.timezone = "Asia/Jakarta"

   [Pdo_mysql]
   pdo_mysql.cache_size = 2000
   pdo_mysql.default_socket =

   [Syslog]
   define_syslog_variables = Off
  
   [mail function]
   SMTP = localhost
   smtp_port = 25
   mail.add_x_header = On
  
   [SQL]
   sql.safe_mode = Off
  
   [ODBC]
   odbc.allow_persistent = On
   odbc.check_persistent = On
   odbc.max_persistent = -1
   odbc.max_links = -1
   odbc.defaultlrl = 4096  
   odbc.defaultbinmode = 1
  
   [MySQL]
   mysql.allow_local_infile = On
   mysql.allow_persistent = On
   mysql.cache_size = 2000
   mysql.max_persistent = -1
   mysql.max_links = -1
   mysql.default_port =
   mysql.default_socket =
   mysql.default_host =
   mysql.default_user =
   mysql.default_password =
   mysql.connect_timeout = 60
   mysql.trace_mode = Off
  
   [MySQLi]
   mysqli.max_persistent = -1
   mysqli.allow_persistent = On
   mysqli.max_links = -1
   mysqli.cache_size = 2000
   mysqli.default_port = 3306
   mysqli.default_socket =
   mysqli.default_host =
   mysqli.default_user =
   mysqli.default_pw =
   mysqli.reconnect = Off
  
   [mysqlnd]
   mysqlnd.collect_statistics = On
   mysqlnd.collect_memory_statistics = Off
  
   [PostgresSQL]
   pgsql.allow_persistent = On
   pgsql.auto_reset_persistent = Off
   pgsql.max_persistent = -1
   pgsql.max_links = -1
   pgsql.ignore_notice = 0
   pgsql.log_notice = 0
  
   [Session]
   session.save_handler = files
   session.save_path = "/tmp"
   session.use_cookies = 1
   session.use_only_cookies = 1
   session.name = PHPSESSID
   session.auto_start = 0
   session.cookie_lifetime = 0
   session.cookie_path = /
   session.cookie_domain =
   session.cookie_httponly =
   session.serialize_handler = php
   session.gc_probability = 1
   session.gc_divisor = 1000
   session.gc_maxlifetime = 1440
   session.bug_compat_42 = Off
   session.bug_compat_warn = Off
   session.referer_check =
   session.entropy_length = 0
   session.entropy_file =
   session.cache_limiter = nocache
   session.cache_expire = 180
   session.use_trans_sid = 0
   session.hash_function = 0
   session.hash_bits_per_character = 5
   url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"



 - Edit file php-fpm.conf
# pico /usr/local/php/etc/php-fpm.conf

pid = /usr/local/php/var/run/php-fpm.pid
   error_log = /usr/local/php/var/log/php-fpm.log
   log_level = notice
   emergency_restart_threshold = 5
   emergency_restart_interval = 15s
   process_control_timeout = 5s
   daemonize = yes
  
   [www]
   listen = 127.0.0.1:9001
   listen.backlog = -1
   listen.allowed_clients = 127.0.0.1
   listen.owner = nobody
   listen.group = nobody
   listen.mode = 0666
  
   user = nobody
   group = nobody
  
   pm = static
   pm.max_children = 20
   pm.max_requests = 2000

   request_terminate_timeout = 0
   request_slowlog_timeout = 0
   slowlog = /usr/local/php/var/log/php-fpm.log.slow
   rlimit_files = 16384
   rlimit_core = 0
   catch_workers_output = yes

   env[HOSTNAME] = $HOSTNAME
   env[PATH] = /usr/local/bin;/usr/bin;/bin
   env[TMP] = /tmp
   env[TMPDIR] = /tmp



 - Buat script file untuk start/stop/restart/reload php-fpm
# pico /etc/init.d/php-fpm
>#!/bin/sh
   prefix=/usr/local/php
   exec_prefix=${prefix}

   php_fpm_BIN=${exec_prefix}/sbin/php-fpm
   php_fpm_CONF=${exec_prefix/etc/php-fpm.conf
   php_fpm_PID=${exec_prefix}/var/run/php-fpm.pid

   php_opts="--fpm-config $php_fpm_CONF"

   wait_for_pid () {
                try=0
                while test $try -lt 35 ; do
                     case "$1" in
                                     'created')       
                                                  if [ -f "$2" ] ; then
                                                                 try=''
                                                                 break
                                                  fi
                                                  ;;
                                     'removed')
                                                  if [ ! -f "$2" ] ; then
                                                                try=''
                                                                break
                                                  fi
                                                  ;;
             esac

                     echo -n .
                     try=`expr $try + 1`
                     sleep 1
                done
   }

   case "$1" in
                start)
                     echo -n "Starting php-fpm"
                     $php_fpm_BIN $php_opts

                     if [ "$?" != 0 ] ; then
                                 echo " failed"
                                 exit 1
                     fi
                     wait_for_pid created $php_fpm_PID
                     if [ -n "$try" ] ; then
                                 echo " failed"
                                 exit 1
                     else
                                 echo " done"
                     fi
                ;;

        stop )
                     echo -n "Gracefully shutting down php-fpm"
                     if [ ! -r $php_fpm_PID ] ; then
                                 echo "warning, no pid file found - php-fpm is not running"
                                 exit 1
                     fi 
                     kill -QUIT `cat $php_fpm_PID`
 
                     wait_for_pid removed $php_fpm_PID
                     if [ -n "$try" ] ; then
                                 echo " failed. use force-quit"
                                 exit 1
                     else
                                 echo " done"
                     fi
                ;;
               
                force-quit)
                     echo -n "Terminating php-fpm"
                     if [ ! -r $php_fpm_PID ] ; then
                                 echo "warning, no pid file found - php-fpm is not running"
                                 exit 1
                     fi

                     kill -TERM `cat $php_fpm_PID`
                     wait_for_pid removed $php_fpm_PID

                     if [ -n "$try" ] ; then
                                 echo " failed"
                                 exit 1
                     else
                                 echo " done"
                     fi
                ;;

                restart)
                     $0 stop
                     $0 start
                ;;

                reload)
                     echo -n "Reload service php-fpm"
                     if [ ! -r $php_fpm_PID ] ; then
                                 echo "warning, no pid file found - php-fpm is not running"
                                 exit 1
                     fi

                     kill -USR2 `cat $php_fpm_PID`

                     echo " done"
                ;;

                *)
                     echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                     exit 1
                ;;
   esac



9. Start PHP-FPM
                # chmod 755 /etc/init.d/php-fpm
                # /etc/init.d/php-fpm start


sekian penjelasan tentang study kasus webserver dan penyelesaiannya
semoga bermanfaat

Post a Comment