I’m currently configuring a cluster to provide high availability web-hosting.

The main issue we’ve experienced is with ensuring that PHP sessions are maintained across the web-servers without having to recode all the sites that are contained on them.

The answer appears to be session_mysql – this is a php module that replaces the “file”session manager with a MySQL backend.

Installing on Debian Etch is easy:

aptitude install build-essential libmysqlclient15-dev php5-dev
  • Cd to the source dir
  • Create the database using the README (remember to change the password!) and execute the following:
phpize

./configure --enable-session-mysql 
--with-php-config=/usr/bin/php-config 
--with-mysql=/usr

make

make install
  • Edit /etc/php5/apache2/php.ini as follows:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
...
...
extension=session_mysql.so
...
...
...
...
[Session]
; Handler used to store/retrieve data.
session.save_handler = "mysql"

As we use Multi-master replication on the MySQL database servers, we can provide transparent session IDs even if one of the web-servers die mid-transfer!

/me loves linux!

PF.