Thursday 16 February 2012

Configuring MODx to run under Tomcat

If you read my article on running PHP under tomcat and debugging it using eclipse you should be up to speed on getting PHP running under Tomcat. An earlier post detailed how to set up Drupal on Tomcat.
This is exactly the same deal!
SO these are the steps:
  1. Set up a folder for your MODx site as a Tomcat Web project where your website folder is "htmldocs" (as it helps you when referring to MODx documentation).
  2. If you have an install of a MODx site which is running under Apache this part is a doddle.
    Simply place ALL the site files into the htmldocs folder.
  3. Start up Tomcat;
  4. Browse to the site & hurah you see your site!
  5. However if you have an index.html file in your root folder you may not see it if index.html comes before your index.php in your welcome file list.
    Either adjust your welcome list or delete the index.html file.
  6. Now when you browse to your index.php page you will see your site.
    Assuming you have your db permissions set up for the web user.
    The php debugging here is a great way to find out where to look as ModX kindly tells you the file and line number where the db access is.
  7. HOWEVER at this point you will find you can see index.php and any other php pages but ModX generates URLs with a .html extension which Tomcat just says do not exist.
    These are " Friendly URLs" in MODx talk.
    This is similar to problems that people running under Apache Httpd encounter.
    If you look for your page on the admin pages (See picture).

    Each page has a number Home=1, "About Us"=12, Solutions=2.
    Yo should be able to get to the pages in question by using the URL <site path>/index.php?id=<doc number>.
    As does using the URL alias seen when editing the resource which is the file refered to by the "Friendly URLs". Try the URL <site path>/index.php?q=<freindly html doc name> (ie. <site path>/index.php?q..
  8. SO lets fix this so the  "Friendly URLs" work.
    We can turn them off but then they are not SEO, having this feature is arguably the most powerful way to have MODx change your urls. When you're using this method, your MODx pages will look and feel just like they were uploaded into a directory on a web server. This is good news for bookmarking and SEO.
    To do this you have to edit your .htaccess file.
    The first hitch will be editing it as eclipse just hides this resource (fix here).

Wednesday 8 February 2012

Tip of the Day - Eclipse Incremental compiler for Java (ECJ)

Try converting your build scripts to use the Eclipse Incremental compiler for Java (ECJ).
I found it in use within the Liferay build scripts.
ECJ, the Eclipse Compiler for Java, is an open source incremental compiler used by the Eclipse JDT. It is an option for Liferay builds and is in many cases faster than Javac or Jikes. The jar for ECJ (ecj.jar) is included in Liferay release 4.4.0 and later and more importantly in Ant 1.8.2 and upwards.
To add it to your Eclipse version of ANT add a global path setting to point to the ecj.jar, which should be where you defined the Tools.jar file to be included.
To enable ECJ in your build you have to set the compiler attribute on the javac task.
Like this:
        <javac
            classpathref="${javac.classpathref}"
            compiler="${javac.compiler}"
            debug="${javac.debug}"
...

In a LifeRay build this is set up in your build.properties as "javac.compiler=org.eclipse.jdt.core.JDTCompilerAdapter" which in turn can be detected using
<whichresource resource="/org/eclipse/jdt/core/JDTCompilerAdapter.class" property="ecj.compiler" />
So you know if you have it installed.

 

Tuesday 7 February 2012

Running LifeRay as a windows service.

This is an ongoing investigation.
SO far the best steps seem to be:
  1. Copy from a tomcat 7 set up the Tomcat7w.exe and all the associated <tomcat>\bin\*.bat files into your Liferay distribution, as they don't seem to come as standard.
  2. Edit the service.bat so that it contains the following lines:
    rem Set default Service name
    set SERVICE_NAME=LiferayTomcat7
    set PR_DISPLAYNAME=Liferay 6.1


    (lines 77-79).
  3. Install the service as normal (here...).
  4. Add the setting in the registry...
    In HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
    Add a setting called "LifeRayMonitoring" like this:
    "C:\development\Java\tomcat\liferay-portal-6.1.0\tomcat-7.0.23\bin\Tomcat7w.exe" //MS//LiferayTomcat7
    This will start the monitoring service for you.
  5. Now the part I am less sure about. The memory settings.
    This is done by editing the Java Options on the Java Tab.
    It should read:
    -Djava.io.tmpdir=C:\development\Java\tomcat\liferay-portal-6.1.0\tomcat-7.0.23\temp
    -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
    -Djava.util.logging.config.file=C:\development\Java\tomcat\liferay-portal-6.1.0\tomcat-7.0.23\conf\logging.properties
    -Xms512M
    -Xmx1024M
    -XX:MaxPermSize=256m
    -Dfile.encoding=UTF8
    -Duser.timezone=GMT

    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000

    The first part is created when you set up the service when startup.bat was run.
    the memory settings are those recommended in the admin manual.
    The three starting with -agentlib are to allow remote debugging against port 8000.
  6. No start remote debugging your portlets (See...)
This is a work in progress but I think it is accurate.

Usefull??? jps - Java Virtual Machine Process Status Tool


jps - Java Virtual Machine Process Status Tool
This tool allows you to list the status of all the JVMs you have running on your PC.
This sounds great until you try to use it.
Then you find it is unable to get any information.
But it is still worth a try...

type <java-home>\bin\jps -mVvl

Friday 3 February 2012

Adding PHP Validation to existing projects

So you have some PHP in a project and it is coded wrong!
What happens???
Well I will tell you it just crashes and ruins your day and you spend an hour looking for the problem, that is what.
Well you need to add the PDT nature to the project but how??
Well there is the hard way as seen here https://www.globalways.net/blog/archives/18-Converting-existing-eclipse-projects-into-PDT-projects.html ... which does work BTW!
Or the easy way....
  1. In Eclipse select the project;
  2. Right mouse click -->Configure-->Add PHP Support...

And that is it all PHPs are now validated ... happy days!

Wednesday 1 February 2012

Using Tomcat Native DLL

Most of the time this error message goes unnoticed:

INFO: The Apache Tomcat Native library which allows optimal performance in
production environments was not found on the java.library.path: C:\...


Time to deal with it!

Downloaded tcnative-1.dll from http://www.apache.org/dist/tomcat/tomcat-connectors/native/1.1.22/binaries/win64/

Here you'll find the binaries for Windows 64-bit platform.

  • x64 is for AMD64/EMT64 architecture (Most current 64 bits architectures).
  • ia64 is for Intel IA64 architecture (Itanium only). 
If you pick the wrong one you will recieve a warning mesage saying you have the wrong architecture.
Go get the other and restart.

I placed mine in the JDK folder as follows "C:\development\java\jdk1.6.0_25\bin" so that it will be reused for all Tomcat instances.

I have notices about a 10% speed up but that is only on the process start. Begining Liferay with the dll gave "INFO: Server startup in 95164 ms", while with out gave "INFO: Server startup in 101845 ms".
Which is 6.7 seconds faster!
I'll have that thanks!