FastCGI merupakan sebuah protokol untuk menjebatani antara program interaktif dengan web server. FastCGI bertujuan untuk mengurangi overhead yang berkaitan dengan interface web server dan program CGI, yang memungkinkan sebuah server untuk menangani beberapa request halaman web dalam suatu waktu.
nginx dan lighttpd memiliki dukungan built-in untuk FastCGI. Untuk web server Apache perlu menggunakan mod_fastcgi atau mod_fcgid
Dalam catatan kali ini, diasumsikan apache dan php sudah terinstall dan berjalan dengan baik. Jika belum, bisa di lihat pada catatan sebelumnya tentang installasi apache dan php.
.:: install mod_fastcgi
pastikan program-program yangdibutuhkan sudah terinstall (httpd-devel and apr-devel required to compile mod_fastcgi)
[root@server01 ~] # wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz[root@server01 ~] # tar -zxvf mod_fastcgi-current.tar.gz[root@server01 ~] # cd mod_fastcgi-2.4.6/[root@server01 mod_fastcgi-2.4.6] # cp Makefile.AP2 Makefile
.:: Compile and install mod_fastcgi for 32 bit system, enter:
[root@server01 ~] # make top_dir=/usr/lib/httpd[root@server01 ~] # make install top_dir=/usr/lib/httpd
.:: Compile and install mod_fastcgi for 64 bit system, enter:
[root@server01 ~] # make top_dir=/usr/lib64/httpd[root@server01 ~] # make install top_dir=/usr/lib64/httpd
.:: konfigurasi mod_fastcgi
[root@server01 ~] # nano /etc/httpd/conf/httpd.conf###tambahkan baris berikutLoadModule fastcgi_module modules/mod_fastcgi.so
.:: simpan dan restart httpd.
.:: konfigurasi agar php berjalan sebagai fastcgi
pertama disable mod_php5
[root@server01 ~] # mv /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.disable
buat shell script pada direktory /var/www/cgi-bin
[root@server01 ~] # nano /var/www/cgi-bin/php.fcgi
###isi file sebagai berikut :
#!/bin/bash
# Shell Script To Run PHP5 using mod_fastcgi under Apache 2.x
# Tested under Red Hat Enterprise Linux / CentOS 5.x
### Set PATH ###
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
### no editing below ###
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI
atur permission file tersebut
[root@server01 ~] # chmod +x /var/www/cgi-bin/php.fcgi
.:: modifikasi document root directory. (you need to use AddHandler and Action directives for mod_fastcgi)
<Directory "/var/www/html">Options -Indexes FollowSymLinks +ExecCGIAllowOverride AuthConfig FileInfoAddHandler php5-fastcgi .phpAction php5-fastcgi /cgi-bin/php.fcgiDirectoryIndex index.php index.htmlOrder allow,denyAllow from all</Directory>
keterangan :
AddHandler php5-fastcgi .php : mengkonfigurasi Apache agar menangani file php (dalam lingkup direktif) dengan ekstensi tertentu sebagai aplikasi FastCGI.
Action php5-fastcgi /cgi-bin/php.fcgi : Direktif ini akan menambahkan action, dimana akan meng-aktifkan cgi-script ketika triggered by the request. cgi-script merupakan URL-path yang telah dikonfigurasi sebagai CGI script menggunakan ScriptAlias. Dalam contoh kasus di atas, permintaan file dengan ekstensi .php akan ditangani oleh script cgi yaitu /cgi-bin/php.fcgi
.:: simpan dan restart httpd.
.:: Berikut contoh untuk konfigurasi pada VirtualHost
NameVirtualHost 10.100.100.99:80<VirtualHost 10.100.100.99:80>ServerName namadomain.comServerAlias www.namadomain.comDocumentRoot "/home/prayoga/www/namadomain.com/htdocs"CustomLog "|/usr/sbin/cronolog /var/apachelogs/prayoga/%Y/%m/%d/namadomain.com.access_log" combinedErrorLog "|/usr/sbin/cronolog /var/apachelogs/prayoga/%Y/%m/%d/namadomain.com.error_log"ScriptAlias /cgi-bin "/home/prayoga/www/namadomain.com/cgi-bin"<Directory "/home/prayoga/www/namadomain.com/htdocs">Options -Indexes FollowSymLinks +ExecCGIAllowOverride AuthConfig FileInfoAddHandler php5-fastcgi .phpAction php5-fastcgi /cgi-bin/php.fcgiDirectoryIndex index.php index.htmlOrder allow,denyAllow from all</Directory></VirtualHost>
.:: buat file php.fcgi pada /home/prayoga/www/namadomain.com/cgi-bin
[root@server01 ~] # nano /home/prayoga/www/namadomain.com/cgi-bin/php.fcgi#!/bin/bashPHP_CGI=/usr/bin/php-cgiPHP_FCGI_CHILDREN=4PHP_FCGI_MAX_REQUESTS=1000export PHP_FCGI_CHILDRENexport PHP_FCGI_MAX_REQUESTSexec $PHP_CGI
.:: set permission
[root@server01 ~] # chmod +x /home/prayoga/www/namadomain.com/cgi-bin/php.fcgi
.:: restart httpd
0 comments:
Post a Comment