HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials

HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials (
-   Installation/Configuration (
-   -   ISPConfig on Debian 6 with optional PHP 5.2 for single webs (

Croydon 29th March 2011 15:01

ISPConfig on Debian 6 with optional PHP 5.2 for single webs
Updating a running debian 5 (lenny) server with client webs on it to debian 6 (squeeze) can lead to problems if some of the webs rely on functions that are deprecated or behave different in debian 6.

I just puglished a blog article in german language here:

It shows how to add php 5.2.17 support to debian 6 with mod_fcgid using apache directives in ISPConfig 2.

Here is the complete shell script that does all the needed steps automatically.
(my original script is in german, so i translated the neccessary parts)

The script does:
- install neccessary packages via apt
- configure mod_fcgid in apache2
- create skeleton fcgi-starter dir
- create script to prepare webs
- download, compile and install php 5.2.17 (32 or 64 bit)

I cannot guarantee this will work for you as it does for me. Use it at your own risk!
Copy the content of the following code section to a shell file (e.g. and run it.
After the script completes you will get a /root/ file that you have to run once for each web you will enable PHP 5.2 for.


if [[ $(id -u) -ne 0 ]] ; then
    echo "Please run this script with root privilegues!" ;
    exit 2 ;

DEBIAN_OK=`cat /etc/debian_version`

if [[ "$DEBIAN_OK" = "" ]] ; then
  echo "This is not a debian server?!...";

read -p "We are going to install some debian packages now! Do you want to proceed (y/N)? " DOIT

if [[ "$DOIT" != "y" ]] ; then
    echo "Abgebrochen." ;
    exit 0 ;

apt-get install -q -y libapache2-mod-fcgid apache2-suexec libpcre3-dev libpcre++-dev libpng12-dev libbz2-dev libcurl4-openssl-dev libc-client2007e-dev libjpeg-dev libgif-dev libgif4 libpthread-stubs0 libpthread-stubs0-dev libx11-dev libxau-dev libxcb1-dev libxdmcp-dev libxpm-dev x11proto-core-dev x11proto-input-dev x11proto-kb-dev xtrans-dev libfreetype6-dev libxml2-dev

a2enmod fcgid
a2enmod suexec

cd /tmp
wget -q "" -O php.tar.bz2
tar xjf php.tar.bz2
cd php-5.2.17

CHECK=`grep "FcgidMaxRequestLen" /etc/apache2/mods-available/fcgid.conf`
if [[ "$CHECK" = "" ]] ; then
  CHECK=`grep "FcgidConnectTimeout" /etc/apache2/mods-available/fcgid.conf`
  if [[ "$CHECK" = "" ]] ; then
    echo "FcgidMaxRequestLen 1073741824" >> /etc/apache2/mods-available/fcgid.conf ;
    sed -i -e "s/^\(\s*FcgidConnectTimeout.*\)$/\1\n  FcgidMaxRequestLen 1073741824/" /etc/apache2/mods-available/fcgid.conf ;
  sed -i -r "s/^\s*FcgidMaxRequestLen\s+\d+.*$/FcgidMaxRequestLen 1073741824/" /etc/apache2/mods-available/fcgid.conf ;

/etc/init.d/apache2 stop
/etc/init.d/apache2 start

CHECK=`uname -a | grep 'amd64'`
if [[ "$CHECK" = "" ]] ; then
  echo "Compiling on 32Bit system" ;
  ./configure --prefix=/usr/share/php52 --datadir=/usr/share/php52 --mandir=/usr/share/man --bindir=/usr/bin/php52 --with-libdir=lib --includedir=/usr/include --sysconfdir=/etc/php52/apache2 --with-config-file-path=/etc/php52/apache2 --with-config-file-scan-dir=/etc/php52/conf.d --enable-libxml --enable-session --with-pcre-regex=/usr --enable-xml --enable-simplexml --enable-filter --disable-debug --enable-inline-optimization --disable-rpath --disable-static --enable-shared --with-pic --with-gnu-ld --with-mysql --with-gd --with-jpeg-dir --with-png-dir --with-xpm-dir --enable-exif --enable-fastcgi --enable-force-cgi-redirect --with-zlib --with-bz2 --with-curl --with-ldap --with-mysqli --with-ttf --with-freetype-dir --enable-soap --enable-sockets --enable-calendar --enable-ftp --enable-mbstring --enable-gd-native-ttf --enable-bcmath --enable-zip --with-pear --with-openssl --with-imap --with-imap-ssl --with-kerberos ;
  echo "Compiling on 64Bit system" ;
  ./configure --prefix=/usr/share/php52 --datadir=/usr/share/php52 --mandir=/usr/share/man --bindir=/usr/bin/php52 --with-libdir=lib64 --includedir=/usr/include --sysconfdir=/etc/php52/apache2 --with-config-file-path=/etc/php52/apache2 --with-config-file-scan-dir=/etc/php52/conf.d --enable-libxml --enable-session --with-pcre-regex=/usr --enable-xml --enable-simplexml --enable-filter --disable-debug --enable-inline-optimization --disable-rpath --disable-static --enable-shared --with-pic --with-gnu-ld --with-mysql --with-gd --with-jpeg-dir --with-png-dir --with-xpm-dir --enable-exif --enable-fastcgi --enable-force-cgi-redirect --with-zlib --with-bz2 --with-curl --with-ldap --with-mysqli --with-ttf --with-freetype-dir --enable-soap --enable-sockets --enable-calendar --enable-ftp --enable-mbstring --enable-gd-native-ttf --enable-bcmath --enable-zip --with-pear --with-openssl --with-imap --with-imap-ssl --with-kerberos ;

make && make install

echo "Compiled and installed PHP. If errors occured here, please press CTRL-C to abort!"
read -p "Creating scripts now... press ENTER to proceed (CTRL+C to cancel)"

cp /etc/php5/apache2/php.ini /etc/php52/apache2/
mkdir /etc/php52/cgi
cp /etc/php5/apache2/php.ini /etc/php52/cgi/

mkdir -p /etc/php52/php-fcgi/

echo '#!/bin/sh

FCGID_STARTER_PHPBIN="/usr/bin/php52/php-cgi -c /etc/php52/cgi/"
' > /etc/php52/php-fcgi/php-starter

chmod 750 /etc/php52/php-fcgi/php-starter
chattr +i /etc/php52/php-fcgi/php-starter

echo '#!/bin/sh
if [ "$WEB_USER" = "" ] ; then
echo "$0 <WEB_USER> <WEB_ID>.";
echo "z. B. $0 web4_ftp_adm web4";
exit 1;
if [ "$WEB_ID" = "" ] ; then
echo "$0 <WEB_USER> <WEB_ID>.";
echo "z. B. $0 web4_ftp_adm web4";
exit 1;
if [ ! -e "/var/www/${WEB_ID}" ] ; then
echo "Directory /var/www/${WEB_ID} is missing."
exit 1;
if [ ! -e "/etc/php52/php-fcgi" ] ; then
echo "Template directory /etc/php52/php-fcgi is missing."
exit 1;
cp -a /etc/php52/php-fcgi /var/www/${WEB_ID}/
chown -R ${WEB_USER}:${WEB_ID} /var/www/${WEB_ID}/php-fcgi
chattr +i /var/www/${WEB_ID}/php-fcgi/php-starter
find /var/www/${WEB_ID}/web -user www-data -exec chown ${WEB_USER}:${WEB_ID} {} \;
echo "Please copy the following code section to the apache directives of ${WEB_ID}:"
echo "====================================="
echo "SuexecUserGroup ${WEB_USER} ${WEB_ID}"
echo "<FilesMatch \.php$>"
echo "    SetHandler fcgid-script"
echo "</FilesMatch>"
echo ""
echo "AddHandler fcgid-script .php .php4 .php5"
echo "FCGIWrapper \"/var/www/${WEB_ID}/php-fcgi/php-starter\" .php"
echo "FCGIWrapper \"/var/www/${WEB_ID}/php-fcgi/php-starter\" .php5"
echo "FCGIWrapper \"/var/www/${WEB_ID}/php-fcgi/php-starter\" .php4"
echo ""
echo "====================================="' > /root/

chmod 700 /root/

echo "ALL DONE!"
echo "Run the command /root/ to prepare a web for PHP 5.2.17."

Qluripax 22nd August 2011 16:45

Thanks for an interesting post. A question to those guys ho know more about ISPconfig: Is this post implementable on a Debian 6 with ISPconfig 3?

till 22nd August 2011 18:17

ISPConfig 3 has fastcgi support out of the box, so there is no need for such a hack in. Just install your ispconfig 3 server as described in the perfect setup guide and you will get fastcgi support.

counterpoint 6th September 2011 17:35

Thanks very much for this helpful script. I ran into a few small issues along the way, and also found it useful to adapt the final result to suit How To Set Up Apache2 With mod_fcgid And PHP5 On Debian Lenny (which also works fine for Squeeze). I already have a script for creating new sites in that environment.

First I found the script wouldn't run, because the target system still had the Squeeze default of the dash shell. That can be changed to defaulting to bash by running:

dpkg-reconfigure dash
and choosing the "no" option. Alternatively, change the shebang on the first line to specifically select bash:

Then the system did not return anything with 64 in it from uname, so the selection of 32 bit or 64 bit compile was going wrong. For that I simply hacked the script to:

# Override choice of 64 bit
#CHECK=`uname -a | grep 'amd64'`

to choose 64 bit.

It also transpired that make was not installed in the target system. That can be checked by:

aptitude search make
and if necessary installed with

aptitude install make
If the result is to be used in conjunction with a system created using the "how to" mentioned above, then individual web sites can be set up exactly as in the "how to" except that the php-fcgi-starter file is changed to:

export PHPRC
exec /usr/bin/php52/php-cgi

(although I actually use different values for the configuration parameters)

All times are GMT +2. The time now is 15:01.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.