Hardcoded

free(DOM);

Archive for August 24th, 2009

Apache 2 PHP module version switcher for Debian/Ubuntu (2)

with 8 comments

Hello again,

I decided to continue my little experiment with PHP and Apache 2, and installed PHP 5.3.0, so that I could enjoy thinks like closures, namespaces and so on, without having to cope with PHP6′s state of development and with it’s bugs. I compiled it from source, using this command:

./configure --with-apxs2=/usr/bin/apxs2 --with-mysql --prefix=/opt/php53  --with-regex --with-libxml-dir=/usr/lib --with-openssl=/usr/lib --with-pcre-regex --with-curl --enable-exif --with-gd --enable-gd-native-ttf --with-gettext --with-mhash --with-imap --with-imap-ssl --enable-mbstring --with-mcrypt --with-mssql --with-mysql --with-mysqli --enable-pcntl --with-pspell --with-libedit --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-tidy --with-xmlrpc --with-xsl --with-openssl=/usr --with-kerberos --enable-embedded-mysqli=shared --with-pdo-mysql=shared --enable-shared=yes --with-interbase=no --with-oci8=no --with-adabas=no --with-pdo-firebird=no --with-pdo-oci=no --with-pdo-odbc=no --with-pgsql=no --with-pdo-mysql --with-pdo-pgsql=no --with-recode=no --with-snmp=no --with-sybase-ct=no

Later edit:

After that run make. Before running sudo make install, please backup the /usr/lib/apache2/modules/libphp5.so file, because it will get overwritten by the install command. After running make install, rename the /usr/lib/apache2/mobules/libphp5.so file to libphp53.so, and copy back the backuped version of libphp5.so.

After that, I created the php53.load and php53.conf files in the /etc/apache2/mods-available/ folder (copy the contents of php5.conf and php5.load and modify the LoadModule directive to include libphp53.so instead of libphp5.so), and updated my shell script to consider this version too. Also, so it happend that I was reading some RSS feeds about some changes in Ubuntu 9.10 (Karmic Koala), and decided to add some eye candy to the script, that is notify-osd. Notify-osd is the program that makes those nice notification bubbles that was introduced in Ubuntu 9.04. I installed the libnotify-bin package, played a little and came up with this version of the apapche-php script:

#!/bin/bash

php5="/etc/apache2/mods-enabled/php5.load"
php53="/etc/apache2/mods-enabled/php53.load"
php6="/etc/apache2/mods-enabled/php6.load"
apache="/var/run/apache2.pid"
old=""

if [ -e "$php5" ]
then
    old="php5"
    enabled5="TRUE"
else
    enabled5="FALSE"
fi
if [ -e "$php53" ]
then
    old="php53"
    enabled53="TRUE"
else
    enabled53="FALSE"
fi

if [ -e "$php6" ]
then
    old="php6"
    enabled6="TRUE"
else
    enabled6="FALSE"
fi

if [ -e "$apache" ]
then
    running="started"
    op="/etc/init.d/apache2 restart"
else
    running="stopped"
    op="/etc/init.d/apache2 start"
fi

echo "5$enabled5"
echo "6$enabled6"

run=$(zenity --title "Switch PHP version"  --list  \
 --text "Apache ($running) with PHP 5/6" --radiolist\
 --column "Active" --column "run" --column "Version" --hide-column=2 \
"$enabled5" "php5" "Apache 2 with PHP 5.2.10" \
"$enabled53" "php53" "Apache 2 with PHP 5.3.0" \
"$enabled6" "php6" "Apache 2 with PHP 6-DEV" \
);

if [ -z $run ]
then
    exit
fi

if [ $run != $old ]
then
    a2enmod $run
    a2dismod $old
fi
$op | zenity --progress --pulsate --auto-kill --auto-close --title "Applying changes ...."

sleep 1

phpversion=""
if [ "php5" == "$run" ]
then
    phpversion="5.2.10"
else
    if [ "php53" == "$run"  ]
    then
	phpversion="5.3.0"
    else
	if [ "php6" == "$run" ]
	then
	    phpversion="6.0.0-DEV"
	fi
    fi
fi

if [ -e "$apache" ]
then
    notify-send "Apache 2 with PHP $phpversion" "Changes applied and server restarted succesfully" -i dialog-info -u normal
    #zenity --info --text "Changes applied"
else
    notify-send "Apache 2" "An error occured, please check the Apache log file for details" -i dialog-error -u critical
    #zenity --error --text "An error occured, check the apache log"
fi

When you run this (with gksudo of course), it displays this list:

Screenshot-Switch PHP version

After checking the version you want, it will display a progress dialog, wait one second and then, the notification daemon will display this bubble on success:

apache-notify-ok

… or this one on failure:

apache-notify-error

Enjoy !

Written by Doru Moisa

August 24, 2009 at 10:26 pm

Posted in Development, linux, php, ubuntu

Follow

Get every new post delivered to your Inbox.