All posts tagged freebsd

Updating ports in FreeBSD 8.0

Ports is the applications repository in FreeBSD. Unlike Ubuntu that provides you with command “apt-get”, in FreeBSD you must manually go to the application folder in “/usr/ports” ( the folder where Ports remain ) and search for the application that you want to install. But what’s the differences between you compile it yourself and using ports. The answer is “dependencies”.

Enough with the introduction, let’s go the main topic. So we are going to update the Ports using cvsup. Yeah… yeah… I know that there are several ways to update the ports, but I prefer to use cvsup ( because it’s the way I taught ). The steps are :
1.Install the cvsup

pkg_add -vr cvsup-without-gui

2.Copy the ports-supfile from example

cp /usr/share/examples/cvsup/ports-supfile .

3.Rehash

rehash

4.Edit the ports-supfile, find the line that say CHANGETHIS.FreeBSD.org. Change it with the mirror that is near you ( I am using BizNet )

5.Run the ports-supfile using cvsup

cvsup -g -L 2 ports-supfile

Wait until the process is complete and your ports will be updated.

Install PHP-FPM di FreeBSD dengan web server Nginx

Setelah mengalami beberapa problem dengan web server Binus Access yang menggunakan Nginx, akhirnya gwa memutuskan untuk mengganti php-cgi menjadi php-fpm.

Untuk mengubah php-cgi menjadi php-fpm ternyata tidak lah sulit, apalagi dengan adanya fitur ports dari FreeBSD. Pertama-tama cukup download file ports php-fpm dari websitenya php-fpm .

Untuk versi nya sendiri bisa disesuaikan dengan versi php anda, kalau gwa sih menggunakan versi php 5.2.10. Jadi hal pertama yang gwa lakukan adalah mendownload php-fpm versi 5.2.10.

Setelah itu tinggal extract aja file php-5.2.10-fpm-0.5.13.tar.gz kemudian pindahin folder php5-fpm nya ke folder /usr/ports/lang. Kemudian tinggal jalankan perintah make dan make install.

Tunggu proses instalasi selesai kemudian ubah file /etc/rc.conf dan tambahkan

php_fpm_enable=”YES”

masuk ke dalam settingan nginx.conf di /usr/local/etc/nginx/nginx.conf dan ubah beberapa settingan di

location / {
root /usr/local/www/nginx;
index index.php index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name;
include fastcgi_params;
}

fastcgi_param SCRIPT_FILENAME /usr/local/www/nginx$fastcgi_script_name; ini adalah tempat folder root web anda berada.

Lalu lanjut dengan edit file php-fpm.conf di /usr/local/etc/php-fpm.conf

nobody –>
nobody –>

ubah nobody menjadi www

www

www

matikan service sebelumnya yaitu php-cgi dan jalankan php-fpm nya

/usr/local/etc/rc.d/php-fpm start

kemudian tinggal testing saja apakah berjalan lancar atau tidak settingannya. Moga-moga lebih stabil dan ga down lagi hohohoho :D

Logs Rotate Nginx di FreeBSD

File logs sering kali menjadi sebuah masalah ketika ukurannya menjadi semakin besar dan memakan sebagian besar hard disk server kita, tetapi di sisi lain file logs juga berguna untuk mencari masalah yang terjadi di server kita.

Gwa juga sempat mengalami beberapa masalah dengan file logs nginx di server FreeBSD. Permasalahan bermula dikarenakan gwa salah mengeset ukuran dari folder ‘/var/logs’ yang hanya berukuran 2 Gb saja ( padahal file logs ukurannya bisa sampai 10 Gb keatas ). Hal tersebut tentu saja mengakibatkan banyak user-user binus-access yang “bernyanyi” karena ga bisa login.

Selain itu ukuran file logs yang semakin lama semakin besar dan terkonsentrasi dalam 1 file tentu saja sangat mempersulit kita dalam melakukan tracing jika terjadi sesuatu, entah itu kena hack, kena dos, kena flood, kompor meleduk, anak hilang, blum sarapan, dll. Oleh karena itu kita akan menggunakan salah satu solusi yaitu rotate file log sehingga file log itu akan dipecah2 menjadi file2 kecil setiap harinya.

Kalau biasanya file logs itu cuma bentuknya “error.log” nanti akan muncul banyak file log sesuai dengan hasil rotate kita, contohnya “error.log.0.bz1″ atau “error.log.1.bz2″.

Jadi langkah pertama yang gwa lakukan adalah mengubah tempat penyimpanan file log ke ‘/usr/local’, kira2 begini lah settingannya di nginx.conf

access_log /usr/local/log/binus-access.com.access.log;
error_log /usr/local/log/binus-access.com.error.log;

setelah itu kita cuma perlu melakukan perubahan di newsyslog.conf supaya bisa merotate log kita, kira-kira begini isi newsyslog.conf ( /etc/newsyslog.conf )

/var/log/all.log                        600  7     *    @T00  J
/var/log/amd.log                        644  7     100  *     J
/var/log/auth.log                       600  7     100  *     JC
/var/log/console.log                    600  5     100  *     J
/var/log/cron                           600  3     100  *     JC
/var/log/daily.log                      640  7     *    @T00  JN
/var/log/debug.log                      600  7     100  *     JC
/var/log/kerberos.log                   600  7     100  *     J
/var/log/lpd-errs                       644  7     100  *     JC
/var/log/maillog                        640  7     *    @T00  JC
/var/log/messages                       644  5     100  *     JC
/var/log/monthly.log                    640  12    *    $M1D0 JN
/var/log/pflog                          600  3     100  *     JB    /var/run/pflogd.pid
/var/log/ppp.log        root:network    640  3     100  *     JC
/var/log/security                       600  10    100  *     JC
/var/log/sendmail.st                    640  10    *    168   B
/var/log/slip.log       root:network    640  3     100  *     JC
/var/log/weekly.log                     640  5     1    $W6D0 JN
/var/log/wtmp                           644  3     *    @01T05 B
/var/log/xferlog                        600  7     100  *     JC
/usr/local/log/*.log    root:wheel      640  7     *    @T00  GJ    /var/run/nginx.pid

jadi sebenarnya yang harus kita tambahkan adalah line terakhir yaitu

/usr/local/log/*.log    root:wheel      640  7     *    @T00  GJ    /var/run/nginx.pid

/usr/local/log/*.log adalah tempat penyimpanan file log kita. Sementara untuk root:wheel itu adalah nama usernya, sementara sisanya ikutin saja la soalnya saya juga ga ngerti hohohoho.

Nah setelah setting itu, kita tinggal menunggu satu hari maka secara otomatis logs file kita akan ter-rotate sendiri. Silakan dicoba sendiri :D

Koneksi ke Microsoft SQL Server dengan PHP di FreeBSD

Beberapa hari yang lalu gwa melakukan perpindahan server Binus Access ke server baru yang menggunakan FreeBSD ( sebelumnya menggunaka Ubuntu Server 8.04 ). Setelah melakukan konfigurasi-konfigurasi dan beberapa persiapan yaitu :

  • Backup database dan file website Binus Access
  • Konfigurasi Nginx ( web servernya ganti Nginx ) agar bisa membaca mod_rewrite
  • Setting NFS dari server asterix ke server Binus Access
  • Setting IP
  • Beberapa settingan kecil lainnya

Jadi setelah dirasa semua persiapan sudah kelar, akhirnya perpindahan server dilakukan yaitu mencabut kabel LAN di server lama dan mencoloknya di server baru ( yap pindahin server cuma begitu saja ). Nah setelah gwa melakukan perpindahan server gwa pun mencoba semua fitur-fitur yang ada di binus-access satu persatu apakah ada yang ga jalan. Ternyata eh ternyata pas gwa tes registrasi untuk user baru terjadilah error dimana yang kalau gwa telusuri dikarenakan server tersebut tidak dapat mengakses server binusmaya ( menggunakan mssql ).

Jadi gwa pun mulai mencek dengan menggunakan phpinfo(); apakah extension mssql sudah terinstall di server FreeBSD tersebut atau blum ( karena seingat gwa pas nginstall php-fpm extension mssql sudah gwa aktifkan ), pas gwa cek ternyata extension mssql sudah terinstall dengan benarnya ( berarti tidak ada kesalahan dengan extension mssql.

Setelah itu gwa pun mulai searching di google dan akhirnya ketemu sebuah artikel yang menyebutkan tentang FreeTDS, gwa sih kurang ngerti juga tentang FreeTDS tapi kalau artikel itu bilang kalau mau connect mssql menggunakan FreeBSD harus menggunakan FreeTDS ini. Oleh karena itu tanpa banyak cing cong langsung saja gwa install FreeTDS lewat ports FreeBSD, neh syntaxnya :

cd /usr/ports/databases/freetds
make install clean

Setelah menginstall FreeTDS langsung saja config freetds.confnya yang terletak di /usr/local/etc/freetds.conf ini isinya config freetds gwa :

#
#
#   $Id: freetds.conf,v 1.11 2005/12/05 21:34:12 freddy77 Exp $
#
# The freetds.conf file is a replacement for the original interfaces
# file developed by Sybase.  You may use either this or the interfaces
# file, but not both.
#
# FreeTDS will search for a conf file in the following order:
#
#     1) check if a file was set programatically via dbsetifile() and
#        is in .conf format, if so use that,
#
#     2) otherwise, if env variable FREETDSCONF specifies a properly 
#        formatted config file, use it,
#
#     3) otherwise, look in ~/.freetds.conf,
#
#     4) otherwise, look in @sysconfdir@/freetds.conf
#
# If FreeTDS has found no suitable conf file it will then search for
# an interfaces file in the following order:
#
#     1) check if a file was set programatically via dbsetifile() and 
#        is in interfaces format, if so use that,
#
#     2) look in ~/.interfaces
#
#     3) look in $SYBASE/interfaces (where $SYBASE is an environment
#        variable)
#
# Only hostname, port number, and protocol version can be specified
# using the interfaces format.
#
# The conf file format follows a modified Samba style layout.  There
# is a [global] section which will affect all database servers and
# basic program behaviour, and a section headed with the database
# server's name which will have settings which override the global
# ones.
#
# Note that environment variables TDSVER, TDSDUMP, TDSPORT, TDSQUERY, 
# and TDSHOST will override values set by a .conf or .interfaces file.
#
# To review the processing of the above, set env variable TDSDUMPCONFIG
# to a file name to log configuration processing.
#
# Global settings, any value here may be overridden by a database
# server specific section
[global]
        # TDS protocol version
	tds version = 4.2

;	initial block size = 512

	# uses some fixes required for some bugged MSSQL 7.0 server that
	# return invalid data to big endian clients
	# NOTE TDS version 7.0 or 8.0 should be used instead
;	swap broken dates = no
;	swap broken money = no

	# Whether to write a TDSDUMP file for diagnostic purposes
	# (setting this to /tmp is insecure on a multi-user system)
;	dump file = /tmp/freetds.log
;	debug flags = 0xffff

	# Command and connection timeouts
;	timeout = 10
;	connect timeout = 10
	
	# If you get out of memory errors, it may mean that your client
	# is trying to allocate a huge buffer for a TEXT field.  
	# (Microsoft servers sometimes pretend TEXT columns are
	# 4 GB wide!)   If you have this problem, try setting 
	# 'text size' to a more reasonable limit 
	text size = 64512

# This is a Sybase hosted database server, if you are directly on the
# net you can use it to test.
[JDBC]
	host = 192.138.151.39
	port = 4444
	tds version = 5.0

# The same server, using TDS 4.2.  Used in configuration examples for the
# pool server, since the pool server supports only TDS 4.2.
[JDBC_42]
	host = 192.138.151.39
	port = 4444
	tds version = 4.2

# The client connecting to the pool server will use this to find its
# listening socket.  This entry assumes that the client is on the same
# system as the pool server.
[mypool]
	host = 127.0.0.1
	port = 5000
	tds version = 4.2

# A typical Microsoft SQL Server 7.0 configuration	
;[MyServer70]
;	host = ntmachine.domain.com
;	port = 1433
;	tds version = 7.0

# A typical Microsoft SQL Server 2000 configuration
[stored]
	host = 10.21.50.16
	port = 1433
	tds version = 8.0
	
# A typical Microsoft SQL Server 6.x configuration	
;[MyServer65]
;	host = ntmachine.domain.com
;	port = 1433
;	tds version = 4.2

jadi buat settingan mssql buat server binusmaya itu gwa letakin di bagian ini :
# A typical Microsoft SQL Server 2000 configuration
[stored]
	host = xx.xx.xx.xx
	port = 1433
	tds version = 8.0

ganti tulisan xx.xx.xx.xx dengan ip server SQL Server nya. Nah sekarang saatnya mencoba melakukan koneksi ( ada sedikit perbedaan cara melakukan koneksi ) begini contoh codingnya dalam PHP :

$host = "stored";
$user = "yourusername";
$pass = "yourpassword";
$db = mssql_connect($host,$user,$pass) or die ("Unable to connect to mssql databases");

Jadi perbedaannya adalah $host yang harus diisi dengan nama yang ada set di freetds.conf tadi, jadi jika pada freetds.conf ada menset namanya menjadi "mssql" maka pada host anda ubah menjadi "mssql". Kira-kira begitulah caranya yang cukup membuat gwa pusing selama 2 jam mencari-cari caranya. Lanjut ngejunk lagi ah :P

Setting mod_rewrite atau SEF Joomla di Nginx

Yap sambil menunggu server World of Warcraft yang tak kunjung up-up gwa buat tutorial sedikit tentang setting mod_rewrite Joomla di Nginx. Sudah pada tau Nginx ? kalau belum tau gwa kasih tau dah. Nginx itu adalah salah satu web server seperti Apache, Lighttpd, Apache Tomcat, Jetty, IIS, Zeus dan lainnya. Nginx ini ( dibacanya Engine X ) kabarnya sih lebih cepat dan stabil dibandingkan Apache yang sudah tersohor sebagai server PHP. Untuk detail lengkap tentang fitur-fiturnya silakan baca link ini.

Kalau pengen liat perbandingan kecepatannya dapat googling sendiri soalnya gwa juga blom coba ngetes kecepatannya soalnya gwa cuma pengen ngetes aja bedanya makai Nginx dan Lighttpd. Setelah gwa menggunakan kedua web server yang katanya lebih “cepat” dari Apache tersebut gwa menemukan salah satu fitur penting yang kurang yaitu kemampuan kedua web server tersebut untuk membaca file .htaccess, dan itu artinya apa ? itu artinya kita tidak bisa langsung memakai fitur-fitur mod_rewrite yang sudah disediakan engine-engine dan framework-framework seperti CakePHP, Joomla, dan WordPress.

Tapi untunglah teknologi sudah maju, cukup search-search dikit ternyata langsung dapat deh tutorial mod_rewrite Joomla di Nginx. Tapi walaupun teknologi sudah maju tapi ternyata tutorial yang didapat tidak cukup maju ( alias dicoba-coba ga jalan ). Jadi daripada ntar ada orang yang bernasib sama kek gwa makanya dengan senang hati gwa bikin ini tutorial hohoho. Ya udah kita back to topic tar kelamaan out of topic.

Nah, jadi untuk membuat mod_rewrite atau fitur SEF Joomla jalan di Nginx kita hanya perlu membuat rulesnya dan dengan sedikit tricky way kita bisa buat semua berjalan seperti di Apache. Kira-kira begini settingan nginx.conf gwa ( gwa ga bakal jelasin cara nginstall Nginx dan setting PHP ) :

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    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"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  binus-access.com v2.binus-access.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
	location / {
		root   /usr/local/www/data;
		index  index.html index.htm index.php;
		error_page 404 = @joomla; 
	}

	location @joomla { 
		rewrite ^(.*)$ /index.php?q=$1 last;
	}

        #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/local/www/nginx-dist;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        
        location ~ \.php$ {
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME /usr/local/www/data$fastcgi_script_name;
		include fastcgi_params;	
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        
#	location ~ \.php$ {
#            root           html;
#            fastcgi_pass   127.0.0.1:9000;
#            fastcgi_index  index.php;
#            fastcgi_param  SCRIPT_FILENAME  /scripts$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;
   #   }
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443;
    #    server_name  localhost;

    #    ssl                  on;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    #    ssl_prefer_server_ciphers   on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

Jadi kalau dilihat-lihat dari settingan nginx.conf gwa, cuma ada 2 hal bagian yang harus diperhatikan yaitu bagian ini :
	location / {
		root   /usr/local/www/data;
		index  index.html index.htm index.php;
		error_page 404 = @joomla; 
	}

	location @joomla { 
		rewrite ^(.*)$ /index.php?q=$1 last;
	}

Kalau ditranslate kira-kira bacanya begini : jika ada error page 404 maka dia akan set rules menjadi @joomla. Semoga tutorial ini berguna, kalau ga jalan coba dilihat-lihat dolo settingannya lagi soalnya TESTED dan WORKS ( silakan ke www.binus-access.com ) itu adalah web yang pakai Nginx. Btw, selain itu ada beberapa web besar yang menggunakan Nginx juga yaitu Kaskus dan WordPress. Jadi itu juga menambah keyakinan gwa untuk menggunakan Nginx ini. Sekian tutorial dari gwa, kalau ada pertanyaan comment ato add YM aja di channel_life.