Instalasi Apache2 suExec PHP5 FastCGI di Debian
From wiki.ngadimin.org
Contents |
Tulisan ini menggunakan informasi sebagai berikut:
- Nama Domain: contoh.com
- Lokasi Direktori Root: /home/ngadimin/sites/www
- Lokasi Direktori cgi-bin: /home/ngadimin/sites/cgi-bin
- User untuk suExec di virtualhost: cecep
Instalasi Apache2
Instalasi apache2 dan kawan-kawan:
apt-get install apache2 apache2-mpm-worker apache2-suexec-custom php5-cgi libapache2-mod-fastcgi
Aktifkan modul-modul yang diperlukan
a2enmod suexec a2enmod fastcgi a2enmod actions a2enmod headers a2enmod include
Mengkonfigurasi mod-fastcgi
Sunting berkas /etc/apache2/mods-available/fastcgi.conf, ubah isinya menjadi seperti berikut:
| Berkas: /etc/apache2/mods-available/fastcgi.conf |
<IfModule mod_fastcgi.c>
FastCgiWrapper /usr/lib/apache2/suexec
FastCgiConfig -pass-header HTTP_AUTHORIZATION -autoUpdate -killInterval 120 -idle-timeout 110
FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule mod_fastcgi.c> |
Mengkonfigurasi mod-suexec-custom
Edit berkas /etc/apache2/suexec/www-data, karena saya meletakkan lokasi document root untuk virtual host saya di /home, maka saya ubah baris pertama di berkas tersebut ke /home.
Membuat Skrip Wrapper
| Berkas: /home/ngadimin/sites/cgi-bin/php5-fcgi |
#!/bin/sh # Configuration directory PHPRC="/etc/php5/cgi" export PHPRC # How much children per manager PHP_FCGI_CHILDREN=4 export PHP_FCGI_CHILDREN # How much requests should be queued per child PHP_FCGI_MAX_REQUESTS=1000 export PHP_FCGI_MAX_REQUESTS # What binary to run with above settings exec /usr/lib/cgi-bin/php5 |
Lalu pastikan pemiliknya sudah tepat:
chown cecep:cecep /home/ngadimin/sites/cgi-bin/ chown cecep:cecep /home/ngadimin/sites/cgi-bin/php5-fcgi
Juga hak aksesnya:
chmod 755 /home/ngadimin/sites/cgi-bin/php5-fcgi
Mengkonfigurasi Virtual Host
Kira-kira contoh berkas utk konfigurasi virtual host di apache adalah sbb:
| Berkas: /etc/apache2/sites-available/contoh.com |
<VirtualHost *:80>
ServerAdmin webmaster@contoh.com
ServerName contoh.com
DocumentRoot /home/ngadimin/sites/www/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/ngadimin/sites/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /home/ngadimin/sites/cgi-bin/
<Directory "/home/ngadimin/sites/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
# Link our wrapperscript to fastcgi
<Location /cgi-bin/php5-fcgi>
SetHandler fastcgi-script
</Location>
# We are running php applications as user/group cecep
SuexecUserGroup "cecep" "cecep"
# Define an action to run on files with handler php5-fastcgi
Action php5-fastcgi /cgi-bin/php5-fcgi
# We put this here for the correct mimetype headers
AddType application/x-httpd-php .php
# for serverwide php access set this here
# otherwise put this line in every VirtualHost that needs php access
AddHandler php5-fastcgi .php
ErrorLog /var/log/apache2/contoh.com_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/contoh.com_access.log combined
</VirtualHost> |
Lalu kita aktifkan virtual host tersebut:
a2ensite contoh.com /etc/init.d/apache2 reload
Test Instalasi
Berkas /home/ngadimin/sites/www/id.php
| Berkas: /home/ngadimin/sites/www/id.php |
<?php
header ("Content-Type: text/plain");
system ("id");
?> |
Jika instalasi berjalan sesuai harapan, ketika mengakses http://contoh.com/id.php, maka yang muncul di browser Anda kira-kira seperti di bawah ini:
uid=1013(cecep) gid=1013(cecep) groups=1013(cecep)
Jika tidak muncul seperti itu, maka Anda harus periksa /var/log/apache2/error.log atau /var/log/apache2/suexec.log.
