Hardcoded

free(DOM);

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 !

Advertisements

Written by Doru Moisa

August 24, 2009 at 10:26 pm

Posted in Development, linux, php, ubuntu

8 Responses

Subscribe to comments with RSS.

  1. […] 3 comments Update, see the part 2, also starring PHP 5.3 […]

  2. […] Apache 2 PHP module version switcher for Debian/Ubuntu (2) « Hardcoded […]

  3. cool

    andrei

    August 25, 2009 at 8:42 am

  4. […] Go here to read the rest: Apache 2 PHP module version switcher for Debian/Ubuntu (2) « Hardcoded […]

  5. […] here:  Apache 2 PHP module version switcher for Debian/Ubuntu (2) « Hardcoded SHARETHIS.addEntry({ title: "Apache 2 PHP module version switcher for Debian/Ubuntu (2) « […]

  6. […] the original: Apache 2 PHP module version switcher for Debian/Ubuntu (2) « Hardcoded SHARETHIS.addEntry({ title: "Apache 2 PHP module version switcher for Debian/Ubuntu (2) « […]

  7. This was really useful, thanks.

    I noticed that it can mess up the version of the PHP command line interface, though.

    When you make install the new php version, it also installs a new version of the php cli. This is probably not desirable behaviour for the module switcher.

    I haven’t analysed exactly what happens, but making a backup of the php script that you get when you type ‘which php’ should be first port of call.

    Then, once you’ve installed the new version, type which php again. I found sometimes ‘which php’ returned ‘/usr/local/bin/php’ and sometimes ‘/usr/bin/php’.

    Anyway, to switch back to the normal php just make sure that which php is linked to the original file. The way I did this was to rename the new file, apt-get remove and reinstall php5-cli, and restarted the system. There’s probably a better way to do it, and the switching could even be incorporated into the script above.

    David Seddon

    August 4, 2010 at 2:34 pm

    • The ” –prefix=/opt/php53″ command line specifies where to put the binaries. In this case, it will install them in /opt/php53, so there is no need to backup

      Ubuntu uses the ‘alternatives’ system; on my computer, the default php cli binary is located at /usr/bin/php, which is a symlink to /etc/alternatives/php, which is also a symlink to /usr/bin/php5.

      So, in order to restore the old cli php, either use the ‘update-alternatives –config php’ command or just redo the symlink by hand.

      Doru Moisa

      August 4, 2010 at 2:55 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: