Mengganti FCGid dengan suPHP di Running Server

Bawaan instalasi virtualmin, untuk handler php adalah menggunakan fcgid. Untuk alasan tertentu, kita perlu mengubahnya dengan suPHP, yang katanya lebih hemat memori LOL LOL LOL.

CATATAN: Server yang saya gunakan adalah Ubuntu 14.04 64 bit dengan RAM 4GB dan 3 core prosesor.

Langsung saja, begini langkah-langkahnya.

  samsul@server:~$ sudo su
  [sudo] password for samsul: 
  root@server:/home/samsul# 
  # apt-get install build-essential apache2-prefork-dev php5-cgi wget
  # cd /usr/src
  # wget -c -t 0 https://www.suphp.org/download/suphp-0.7.1.tar.gz
  # tar -xzf suphp-0.7.1.tar.gz
Catatan: Versi lebih baru tersedia, yaitu 0.7.2. Namun saat saya coba sepertinya versi tersebut tidak dapat dicompile, dan belum tersedia patch-nya.
  # wget -O fix.diff https://sites.google.com/site/sudosuin/fix.diff
  # patch -Np1 -d suphp-0.7.1 < fix.diff
  patching file configure.ac
  patching file src/Makefile.am
  patching file src/Makefile.in
  # cd suphp-0.7.1
  # ./configure --prefix=/usr --sysconfdir=/etc --with-apache-user=www-data --with-setid-mode=paranoid --with-apxs=/usr/bin/apxs2
  # make
  # cp /usr/include/apr-1.0/*.h /usr/include/apache2
  # make
  # make install
  # cp doc/suphp.conf-example /etc/suphp.conf
  # vim /etc/suphp.conf

Ganti beberapa parameter ini

  webserver_user=wwwrun

menjadi

  webserver_user=www-data

yang ini

  x-httpd-php="php:/usr/bin/php"

diganti menjadi

  application/x-httpd-suphp="php:/usr/bin/php-cgi"

ubah juga loglevel

  loglevel=info

menjadi

  loglevel=warn

Umask

  umask=0077

Menjadi

  umask=0022

Sesuaikan yang ini

  allow_file_group_writeable=true
  allow_file_others_writeable=false
  allow_directory_group_writeable=true
  allow_directory_others_writeable=false
  # vim /etc/apache2/mods-available/suphp.load

Isi dengan baris berikut, lalu simpan

  LoadModule suphp_module /usr/lib/apache2/modules/mod_suphp.so
  # vim /etc/apache2/mods-available/suphp.conf

Isi file tersebut dengan kode berikut

suphp.conf
<IfModule mod_suphp.c>
 
  AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml
  suPHP_AddHandler application/x-httpd-suphp
 
  <Directory />
    suPHP_Engine on
  </Directory>
 
# By default, disable suPHP for debian packaged web applications as files
# are owned by root and cannot be executed by suPHP because of min_uid.   
 
  <Directory /usr/share>
    suPHP_Engine off   
  </Directory>
 
# 
# Use a specific php config file (a dir which contains a php.ini file)
#       suPHP_ConfigPath /etc/php4/cgi/suphp/ 
# 
# Tells mod_suphp NOT to handle requests with the type <mime-type>.
#       suPHP_RemoveHandler <mime-type>
 </IfModule>
  # a2enmod suphp

Selanjutnya edit tiap berkas konfigurasi VirtualHost, misal untuk domain wiki.samsul.web.id

  # vim /etc/apache2/sites-available/wiki.samsul.web.id.conf

Tambahkan direktif suPHP_UserGroup beserta nama pengguna tiap VirtualHost masing-masing,

<IfModule mod_suphp.c>
  suPHP_UserGroup wiki wiki
</IfModule>
#AddHandler fcgid-script .php
#AddHandler fcgid-script .php5
#FCGIWrapper /home/wiki/fcgi-bin/php5.fcgi .php
#FCGIWrapper /home/wiki/fcgi-bin/php5.fcgi .php5
  sed -i '/IPCCommTimeout/d' /etc/apache2/sites-enabled/*
  sed -i '/FcgidMaxRequestLen/d' /etc/apache2/sites-enabled/*
  sed -i '/php_admin_flag/d' /etc/apache2/sites-enabled/*
  sed -i '/php_admin_value/d' /etc/apache2/sites-enabled/*
  # a2dismod fcgid
  # service apache2 restart

Sekarang server sudah beralih menggunakan suPHP.

Referensi

~~DISQUS~~