Sunday, November 6, 2011

La donna è mobile...

Reactions: 

... Qual piuma al vento...

In one of the previous blog entries I said I will not try to run Joomla 1.5 on Quercus, as it is yesterday's news. Well, I changed my mind :) I am happy I did as I found out many new things about Quercus and its relationship with PHP.

Here are several things one needs to take into account when attempting to install Joomla 1.5 on Quercus/Resin/Caucho

1. Static Variables

Quercus has a fancy way to treat the static variables. One cannot declare static variables inside functions as Joomla does all over the place. As Quercus translates to Java, it attempts to declare them as static at the class level. If you have several statics with the same name, as factory.php does, Quercus gets thoroughly confused and throws a stack overflow exception !

Joomla 1.5 needs to be fixed and any static variable declared inside a function must be transferred outside. For example:

static $apinstance;  
        function &getApplication($id = null, $config = array(), $prefix='J')
{

if (!is_object(self::$apinstance))
{
jimport( 'joomla.application.application' );
if (!$id) {
JError::raiseError(500, 'Application Instantiation Error');
 
}
self::$apinstance = JApplication::getInstance($id, $config, $prefix);
}
return self::$apinstance;
 
}
You will have to hunt all these instances and fix them. Quite painful.

2. Database connection

For some reason Joomla cannot pick up the database configuration from configuration.php. It picks up the database name but not the host/user name/password. One has to define the database connection as a resource in quercus:

Create a resin-web.xml under WEB-INF with the following contents:


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://caucho.com/ns/resin">
<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list>
<rewrite-dispatch>
<dispatch regexp="\.(php|gif|css|jpg|png|ico|js|html|htm|txt)"/>
<forward regexp="^/" target="/index.php?q="/>
</rewrite-dispatch>

  <database jndi-name="jdbc/mysql">
    <driver type="org.gjt.mm.mysql.Driver">
      <url>jdbc:mysql://yourip:3306/</url>
      <user>your user</user>
      <password>yourpwd</password>
    </driver>

  </database>
  <servlet-mapping url-pattern="*.php"
                   servlet-class="com.caucho.quercus.servlet.QuercusServlet">
    <init>
      <ini-file>WEB-INF/php.ini</ini-file>
      <database>java:comp/env/jdbc/mysql</database>
      
    </init>
  </servlet-mapping>
  
</web-app>

This will create a database resource for your database. You will give the database name in configuration.php as usual.

3. mbstring.language

mbstring.language must be defined in php.ini to avoid the warning below. Refer to resin-web.xml above for how to configure php.ini.

The value must be: mbstring.language=neutral


















After these 3 aspects are fixed, one can attempt the installation. One problem here: if you are on Mac, the sample data button does not work, as the installation program assumes IE. You can pick up the SQL script, replace the table prefix and run it manually.

All these aspects fixed, Joomla 1.5 installs nicely on Quercus. It will probably take you way less time, as you'll not have to debug PHP via the PHP interpreter in Quercus, to realize that stack overflow actually means "Unable to load application" or "Application Instantiation Error". If you ever got the "Infinite loop detected in JError", it is the same thing. Something happened and the JApplication object cannot be instantiated. In this case Quercus couldn't create the static field "$instance". Some other time is the database...

And here is joomla on localhost:8080, under Caucho Resin/Quercus:













Time to go get some Fajitas. "Muta d'accento — e di pensiero" costed me almost the whole day ! :)

0 comments:

Post a Comment