This article covers a Hippo CMS version 7.7. There's an updated version available that covers our most recent release.

Use PHP in combination with Hippo CMS 

Hippo CMS is Java based. It runs in a JVM, components are written in Java, and the pages are rendered using JSP and/or Freemarker templates. But if you have to or want to use PHP because of, for instance, company policy, a PHP environment of the current website, or you are a PHP expert, you can still use Hippo CMS.

There are numerous possibilities for using PHP. Some examples are:

The example using REST calls to get content makes use of the online demo of Hippo CMS. For the other ones, you will need a local Hippo CMS instance. The last two examples, using the repository directly and the templates in PHP also need the PHP/Java bridge.

Setting up a local Hippo CMS instance

  • First, follow the Hippo Trail Baby Steps.

  • Install the PHP/Java Bridge. This is only needed for the last two examples. Download the files JavaBridge.jar, php-script.jar, php-servlet.jar and Java.inc from: http://php-java-bridge.sourceforge.net/pjb/download.php

  • Copy or move the jar files to your archetype to site/src/main/webapp/WEB-INF/lib/ and the Java.inc file to site/src/main/webapp/java/

  • Add the following to the site/src/main/webapp/WEB-INF/web.xml file:

    <!-- the following 8 lines extend the servlet spec 2.2 "url-pattern" to handle PHP PATH_INFO: *.php/something?what=that. Remove them, if you don't need this feature. -->
    <filter>
        <filter-name>PhpCGIFilter</filter-name>
        <filter-class>php.java.servlet.PhpCGIFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PhpCGIFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- the following adds the JSR223 listener. Remove it if you don't want to use the JSR223 API -->
    <listener>
        <listener-class>php.java.servlet.ContextLoaderListener</listener-class>
    </listener>

    <!-- the back end for external (console, Apache/IIS-) PHP scripts; remove it if you don't need this -->
    <servlet>
        <servlet-name>PhpJavaServlet</servlet-name>
        <servlet-class>php.java.servlet.PhpJavaServlet</servlet-class>
    </servlet>

    <!-- runs PHP scripts in this web app; remove it if you don't need this -->
    <servlet>
        <servlet-name>PhpCGIServlet</servlet-name>
        <servlet-class>php.java.servlet.fastcgi.FastCGIServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>


    <servlet-mapping>
        <servlet-name>PhpJavaServlet</servlet-name>
        <url-pattern>*.phpjavabridge</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>PhpCGIServlet</servlet-name>
        <url-pattern>*.php</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.php</welcome-file>
    </welcome-file-list>
  • Build and run

mvn clean install
mvn -P cargo.run
  • Done!