Konfigurasi PHP FastCGI pada Apache

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 berikut
LoadModule 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 +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
DirectoryIndex index.php index.html
Order allow,deny
Allow 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 115.69.218.165:8080

<VirtualHost 115.69.218.165:8080>
ServerName open.stylekita.com
ServerAlias open.stylekita.com
DocumentRoot "/home/prayoga/www/open.stylekita.com/htdocs"
CustomLog "|/usr/sbin/cronolog /var/apachelogs/prayoga/%Y/%m/%d/open.stylekita.com.access_log" combined
ErrorLog "|/usr/sbin/cronolog /var/apachelogs/prayoga/%Y/%m/%d/open.stylekita.com.error_log"
ScriptAlias /cgi-bin "/home/prayoga/www/open.stylekita.com/cgi-bin"

<Directory "/home/prayoga/www/open.stylekita.com/htdocs">
Options -Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php.fcgi
DirectoryIndex index.php index.html
Order allow,deny
Allow 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/bash
PHP_CGI=/usr/bin/php-cgi
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000
export PHP_FCGI_CHILDREN
export PHP_FCGI_MAX_REQUESTS
exec $PHP_CGI

.:: set permission


[root@server01 ~] # chmod +x /home/prayoga/www/namadomain.com/cgi-bin/php.fcgi

.:: restart httpd

Blog Wowrack Indonesia

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

See More

Latest Article

Optimalkan kinerja bisnis sesuai kebutuhan Anda dengan layanan fleksibel Wowrack