Category Archives: Hosting

mod_fastcgi vs mod_fcgid

Apache can be configured to run FastCGI with two modules: mod_fastcgi and mod_fcgid. The difference is that mod_fcgid passes just one request to the FCGI server at a time while mod_fastcgi passes several requests at once, the latter is usually better for PHP, as PHP can manage several request using several threads and opcode caches like APC usually work only with threads and not with processes. This means that using mod_fcgid you end up having many PHP processes which all have their very own opcode cache.”

mod_fastcgi with PHP-FPM on Centos

yum install php-fpm
chkconfig –levels 235 php-fpm on
vi /etc/php-fpm.d/www.conf
;listen = 127.0.0.1:9000
listen = /tmp/php5-fpm.sock
pm.status_path = /status
ping.path = /ping

service php-fpm start

yum install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum install mod_fastcgi # Get mod_fastcgi from rpmforge or compile yourself

yum install libtool httpd-devel apr-devel apr
wget http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz
tar -zxvf mod_fastcgi-current.tar.gz
cd mod_fastcgi*
make top_dir=/usr/lib64/httpd
make install top_dir=/usr/lib64/httpd

mv /etc/httpd/conf.d/{php.conf,php.conf.disable}
mkdir /usr/lib/cgi-bin/
vi /etc/httpd/conf.d/mod_fastcgi.conf
LoadModule fastcgi_module modules/mod_fastcgi.so


DirectoryIndex index.php index.html index.shtml index.cgi
AddHandler php5-fcgi .php
Action php5-fcgi /php5-fcgi
Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi
FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi -socket /tmp/php5-fpm.sock -pass-header Authorization

# For monitoring status with e.g. Munin

SetHandler php5-fcgi-virt
Action php5-fcgi-virt /php5-fcgi virtual

service httpd restart

nginx status plugin for munin

nginx -V 2>&1 | grep -o with-http_stub_status_module
vi /etc/nginx/nginx.conf
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
allow your_IP;
deny all;
}
service nginx reload

vi /etc/munin/plugin-conf.d/nginx_
[nginx*]
env.url http://localhost/nginx_status

cd /etc/munin/plugins/
sudo ln -sf /usr/share/munin/plugins/nginx_* .
service munin-node restart

apache calculate MaxClients count

To get a rough idea of how to set the MaxClients directive, it is best to find out how much memory the largest apache thread is using. Then stop apache, check the free memory and divide that amount by the size of the apache thread found earlier. It usually work only for mod_php mode:

#!/bin/bash
echo “This is intended as a guideline only!”
if [ -e /etc/debian_version ]; then
APACHE=”apache2″
elif [ -e /etc/redhat-release ]; then
APACHE=”httpd”
fi
RSS=$(ps -aylC $APACHE |grep “$APACHE” |awk ‘{print $8’} |sort -n |tail -n 1)
RSS=$(expr $RSS / 1024)
echo “Stopping $APACHE to calculate free memory”
/etc/init.d/$APACHE stop &> /dev/null
MEM=$(free -m |head -n 2 |tail -n 1 |awk ‘{free=($4); print free}’)
echo “Starting $APACHE again”
/etc/init.d/$APACHE start &> /dev/null
echo “MaxClients should be around” $(expr $MEM / $RSS)

simple ispconfig install debian

mkdir /opt/phpfcgi-5.4.12
mkdir /usr/local/src/php5-build
cd /usr/local/src/php5-build
wget http://de.php.net/get/php-5.4.12.tar.bz2/from/this/mirror -O php-5.4.12.tar.bz2
tar jxf php-5.4.12.tar.bz2

apt-get install build-essential
apt-get build-dep php5
apt-get install libfcgi-dev libfcgi0ldbl libjpeg62-dbg libmcrypt-dev libssl-dev libc-client2007e libc-client2007e-dev
ln -s /usr/lib/libc-client.a /usr/lib/x86_64-linux-gnu/libc-client.a

./configure \
–prefix=/opt/phpfcgi-5.4.12 \
–with-pdo-pgsql \
–with-zlib-dir \
–with-freetype-dir \
–enable-mbstring \
–with-libxml-dir=/usr \
–enable-soap \
–enable-calendar \
–with-curl \
–with-mcrypt \
–with-zlib \
–with-gd \
–with-pgsql \
–disable-rpath \
–enable-inline-optimization \
–with-bz2 \
–with-zlib \
–enable-sockets \
–enable-sysvsem \
–enable-sysvshm \
–enable-pcntl \
–enable-mbregex \
–with-mhash \
–enable-zip \
–with-pcre-regex \
–with-mysql \
–with-pdo-mysql \
–with-mysqli \
–with-jpeg-dir=/usr \
–with-png-dir=/usr \
–enable-gd-native-ttf \
–with-openssl \
–with-fpm-user=www-data \
–with-fpm-group=www-data \
–with-libdir=/lib/x86_64-linux-gnu \
–enable-ftp \
–with-imap \
–with-imap-ssl \
–with-kerberos \
–with-gettext \
–enable-cgi

make
make install

php.ini: cp -v /usr/local/src/php5-build/php-5.4.12/php.ini-production /opt/phpfcgi-5.4.12/lib/php.ini

cd /tmp
wget http://www.ispconfig.org/downloads/ISPConfig-3-stable.tar.gz
tar xvfz ISPConfig-3-stable.tar.gz
cd ispconfig3_install/install

/opt/php-5.3.22/bin/php -q install.php

Kloxo MR – kloxomr

This is special edition (fork) of Kloxo with many features not existing on Kloxo official release (6.1.12+). This fork named as Kloxo-MR (meaning ‘Kloxo fork by Mustafa Ramadhan’)

cd /
yum update -y

yum install yum-utils yum-priorities vim-minimal subversion curl zip unzip -y
yum install telnet -y

setenforce 0
echo ‘SELINUX=disabled’ > /etc/selinux/config

cd /etc/yum.repos.d/

wget https://github.com/mustafaramadhan/kloxo/raw/release/kloxo-mr.repo –no-check-certificate

yum install kloxomr

run  Kloxo install script:

 

sh /usr/local/lxlabs/kloxo/install/setup.sh