Ich beschäftige mich - nicht nur aus meinem Job heraus - mit leichtgewichtiger Softwareentwicklung und dem Java-Build-(Lifecycle-)Management. Hier möchte ich neue Ideen und Best-Practices vorstellen.

Montag, 12. April 2010

Running Mediawiki on Tomcat

The idea of running a PHP-Application on a Java application server might seem weird to most people – but if you have a working Java infrastructure and are familiar with setting up Tomcat this might be an option to avoid the “compiling PHP/Apache – hassle”. Follow my step-by-step guide to get Mediawiki up and running on Tomcat.

1. Install Resin Quercus

Make sure you have a proper JDK and a recent Tomcat installed. Download the latest Quercus Release and extract it into a folder mediawiki the Tomcat’s /webapps folder (hint: it’s a ZIP-file, rename and unzip).

2. Extract Mediawiki

Download the latest Mediawiki and extract in the mediawiki – Folder created in the last step. In your Tomcat installation, you should now have a mediawiki – folder in which you have a Mediawiki-Installation plus two special folders, WEB-INF and META-INF. Update the web.xml with the following bold part.

3. Configure Quercus

Quercus comes with a preconfigured web.xml in the WEB-INF – folder. We have to “pimp” it a little to make Mediawiki run properly.

<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<!--
Tells Quercus to use the following JDBC database and to ignore the
arguments of mysql_connect(). We'll configure the MySQL database
pool in the next step.
-->
<init-param>
<param-name>database</param-name>
<param-value>jdbc/mediawiki</param-value>
</init-param>

</servlet>
<!--
Tells the Quercus Servlet to parse all files ending on .php
-->
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<!--
Tells the Quercus Servlet to parse all Requests starting with index.php/
We need this to support the pretty urls in Mediawiki
-->
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>index.php/*</url-pattern>
</servlet-mapping>

</servlet>

3. Configure MySQL as JNDI-Datasource in Tomcat

In order to unleash the full power of a JEE-powered Mediawiki, we’ll configure a pooled MySQL datasource. In order to access MySQL from Tomcat, we need a proper MySQL database driver. Download it here and place the contained mysql-connector-java-5.1.12-bin.jar in Tomcat’s /lib directory. Prepare a MySQL database to hold the Mediawiki database tables. Create a MySQL user if necessary.

Then place a file named context.xml in the /webapps/mediawiki/META-INF folder. Fill the variables with values matching your environment:

<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/mediawiki" auth="Container"
type="javax.sql.DataSource"
maxActive="20" maxIdle="2" maxWait="10000"
username="<<MYSQL_USERNAME>>" password="<<MYSQL_PASSWORD>>"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://<<MYSQL_HOST>>:<<MYSQL_PORT>>/<<MYSQL_DATABASE_NAME>>"/>
</Context>

4. Run the Mediawiki-Installer

Fire up Tomcat and go to http://localhost:8080/mediakwiki/config/index.php. Follow the installation steps of Mediawiki. For debugging purposes place a phpinfo.php file in the /webapps/mediawiki folder:

<?php
phpinfo();
?>

Enjoy! In the next post I’ll write some lines about Single-Sign-On with NTLM and Tomcat/Apache/Mediawiki.

Hallo Besucher, schreibe einen Kommentar! »