IT Consultant – Java, J2EE, IBM WebSphere Portal, Lotus Notes/Domino
RSS icon Home icon
  • Installing Tomcat 6 on Debian Squeeze

    (10 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Posted on 13 March 2010 Sebastian Thomschke*/?> 10 comments

    This post describes how to setup Tomcat 6 on Debian Squeeze. The configured Tomcat serves requests on port 80 without the need of an additional web server. This is especially good for virtual servers (VPS) providing limit memory. It also has multiple virtual hosts configured, each with it’s own webapp with context root / and optional support for PHP via the Quercus PHP implementation.

    Installing Sun Java 6

    Ensure the non-free section is enabled for the APT repository configuration in /etc/apt/sources.list, e.g. “deb testing main contrib non-free”

    apt-get update
    apt-get install sun-java6-jdk
    echo 'JAVA_HOME="/usr/lib/jvm/java-6-sun"' >> /etc/environment
    echo 'JRE_HOME="/usr/lib/jvm/java-6-sun/jre"' >> /etc/environment

    Installing Tomcat 6

    apt-get install tomcat6 tomcat6-admin
    /etc/init.d/tomcat6 stop

    Creating standard Tomcat directory layout (optional)

    mkdir /opt/tomcat
    cd /opt/tomcat
    ln -s /etc/tomcat6/ conf
    ln -s /usr/share/tomcat6/bin/ bin
    ln -s /usr/share/tomcat6/lib/ lib
    ln -s /var/lib/tomcat6/webapps webapps
    ln -s /var/log/tomcat6/ logs

    Creating a Tomcat admin user

    In /opt/tomcat/conf/tomcat-users.xml add an entry like:

    <user name="ADMIN_USERNAME" password="ADMIN_PASSWORD" roles="admin,manager" />

    Setting up virtual hosts

    For each virtual host execute the following command. Replace “” with the desired virtual host name, but omit the “www.” part.

    mkdir -p /opt/tomcat/

    In the <Engine> tag of “/opt/tomcat/conf/server.xml” add one host entry for each virtual host.

    <Host name="" appBase="/opt/tomcat/">
        <Valve className="org.apache.catalina.valves.AccessLogValve" prefix="mydomain_access_log." suffix=".txt" pattern="common"/>

    The <Alias> tag tells Tomcat to redirect from to
    The <Valve> tag enables access logging in the standard logging format.

    Using xinetd to configure port 80 for Tomcat

    Binding a service on port 80 requires root permissions. Thus we use port forwarding to “bind” Tomcat to port 80. My VPS does not support the use of “iptables -j REDIRECT” therefore I am using xinetd as a web proxy.
    Ensure that no other service is listening on port 80/443:

    netstat -pan | grep ":80\|:443"

    Register the required xinetd services:

    echo echo "
    service www
            socket_type     = stream
            protocol        = tcp
            user            = root
            wait            = no
            bind            =
            port            = 80
            redirect        = localhost 8080
            disable         = no
            flags           = REUSE
            log_type        = FILE /var/log/wwwaccess.log
            log_on_success  -= PID HOST DURATION EXIT
            per_source      = UNLIMITED
            instances       = UNLIMITED
    service https
            socket_type     = stream
            protocol        = tcp
            user            = root
            wait            = no
            bind            =
            port            = 443
            redirect        = localhost 8443
            disable         = no
            flags           = REUSE
            log_type        = FILE /var/log/httpsaccess.log
            log_on_success  -= PID HOST DURATION EXIT
            per_source      = UNLIMITED
            instances       = UNLIMITED
    " > /etc/xinetd.d/tomcat
    /etc/init.d/xinetd restart

    If you want to use a different service name, e.g. “tomcat” instead of “www” you must add this service to /var/services, e.g. “tomcat 80/tcp”
    In /opt/tomcat/conf/server.xml modify the <Connector> as follows:

    <Connector port="8080" protocol="HTTP/1.1"
                   redirectPort="8443" proxyPort="80" address="" />

    This binds Tomcat to localhost. It also tells Tomcat that port 80 is the proxy port which is necessary for correct URL generation.
    From now on the Tomcat admin applications are only accessible via localhost. You can use SSH port forwarding to still access the applications from your workstation’s web browser. E.g. if you are using PuTTY you can use this command line option “-L 8080:localhost:8080” to forward the server’s local 8080 port to your workstation’s local 8080 port. On your workstation’s browser you then simply enter http://localhost:8080/manager/html and are connected to the server’s Tomcat admin application.

    Enabling PHP support (optional)

    Download Quercus.

    mkdir -p /opt/downloads
    wget -o /opt/downloads/quercus-4.0.3.war

    Install Quercus as a shared library.

    unzip -j /opt/downloads/quercus-4.0.3.war \*.jar -d /opt/tomcat/lib

    Enable PHP support for the virtual hosts by installing the quercus web.xml. For each virtual host execute:

    unzip /opt/downloads/quercus-4.0.3.war *web.xml -d /opt/tomcat/

    Starting Tomcat

    /etc/init.d/tomcat start


  • [Solved] Blank Pages with WordPress 2.6.x

    1 Star2 Stars3 Stars4 Stars5 Stars
    Posted on 13 September 2008 Sebastian Thomschke*/?> 2 comments

    After upgrading to WordPress 2.6 it occasionally happend that an empty page was displayed in the browser when navigating through the blog or working in the admin area. Refreshing the browser using CTRL+F5 usually helped in that case. Today I upgraded to WordPress 2.6.2 and I was not able to access the plug-ins page of the admin area anymore. No matter how often I refreshed the page in the browser it stayed blank.
    First I searched the web for possible solutions. I found quite a number of discussions giving tips about this widely known problem but unfortunately none of these solutions helped in my case.
    So I again started debugging the WordPress code and finally found the lines of code causing the trouble. The problem are (object) casts in the wp-includes/taxonomy.php file that transform an array into an object:

    $wp_taxonomies['category'] = (object) array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count');
    $wp_taxonomies['post_tag'] = (object) array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count');
    $wp_taxonomies['link_category'] = (object) array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false);

    Since I don’t get any error messages neither on the screen nor in the log files I have no idea why these casts fail. The PHP version used to serve the site is the latest stable 5.x release from
    As a workaround I introduced a function that does also transforms an array into an object but does not rely on the casting mechanism.

    function arr2obj($arr) {
    	foreach ($arr as $k => $v) $obj -> {$k} = $v;
    	return $obj;
    $wp_taxonomies['category'] = arr2obj(array('name' => 'category', 'object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count'));
    $wp_taxonomies['post_tag'] = arr2obj(array('name' => 'post_tag', 'object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count'));
    $wp_taxonomies['link_category'] = arr2obj(array('name' => 'link_category', 'object_type' => 'link', 'hierarchical' => false));
  • Making the DD Sitemap Generator Plug-in work with multilingual blogs

    (2 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Posted on 1 May 2008 Sebastian Thomschke*/?> 3 comments

    To create a bilingual blog with WordPress I am using the Language Switcher Plug-in. This plug-in allows you to put content in more than one language into the post title and content fields by surrounding the localized texts with special tags indicating their language (e.g. “[ lang_en]Hello World[ /lang_en][ lang_de]Hallo Welt[ /lang_de]”). When the posts are viewed in the browser the plug-in will determine the active language and strip off the texts specified in all other languages on the fly.

    I am using the great DD Sitemap Generator Plug-in for WordPress to automatically render a site map based on the posts, pages and categories created in my blog. The problem however is that the generated site map is not language aware and displays the page/post titles and category names including the tags and the texts of all languages at once.

    To solve this I started digging a bit into the code of WordPress and the Language Switcher Plug-in. The Language Switcher Plug-in achieves the on-the-fly processing of multilingual texts by hooking itself into the so called Filters API which is something like an event-based callback mechanism. Plug-ins can signal their interest in a certain text filter event by calling the add_filter(the_event_id, the_name_of_a_function_to_callback) function provided by the WordPress API to register one if it’s functions that will be invoked by WordPress when the filter event occurs. Besides registering for filter events, plug-ins can also fire such events by calling the apply_filters(the_event_id, the_text_to_be_filtered). WordPress will then apply all registered filters to the text passed over and the apply_filters will return a “filtered” version of the passed text. When rendering the title of a post or page WordPress fires the filter event “the_title” allowing plug-ins to process/modify the title before it is actually displayed. Therefore the Language Switcher Plug-in registers itself to this event and a lot of others to be able to strip off the language tags and the texts in languages other than the currently active one.

    Unfortunately the DD Sitemap Generator Plug-in is currently not applying the respective filters when rendering the site map. Therefore the Language Switcher Plug-in is not aware of it and as a result the site map shows all translations of a category name or page/post title at the same time no matter which language is currently active.

    To solve this problem I analyzed the source code of the DD Sitemap Generator Plug-in and added the missing apply_filters calls where appropriate. You can follow these steps in case you are having the same issue:

    1. Open the file <wordpress_root>/wp-content/plugins/sitemap-generator/sitemap-generator.php (or <wordpress_root>/wp-content/plugins/dd-sitemap-gen/dd-sitemap-gen.php) in an editor
    2. Locate the text
         $tmp_array[‘title’] = $pages[$k]->post_title;
      and replace it with
         $tmp_array[‘title’] = apply_filters(‘the_title’, $pages[$k]->post_title);
    3. Locate the text
         $tmp_array[‘title’] = $cat_data[$c][‘cat_name’];
      and replace it with
         $tmp_array[‘title’] = apply_filters(‘the_category’, $cat_data[$c][‘cat_name’]);
    4. Locate the text
         $tmp_array[‘title’] = $posts[$k]->post_title;
      and replace it with
         $tmp_array[‘title’] = apply_filters(‘the_title’, $posts[$k]->post_title);
    5. Save the file and you are done.

    If you are encountering similar problems with other plug-in you can use the same approach to make them play nicely with the Language Switcher Plug-in.

  • [Solved] WordPress 2.5 One-Click Plug-in Upgrades – Could not create directory

    (6 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Posted on 25 April 2008 Sebastian Thomschke*/?> 42 comments

    Some days ago I upgraded my WordPress installation to the new 2.5 release. Being a lazy guy I of course wanted to use the new one-click plug-in upgrade feature to update several plug-ins. Trying to one-click update some of the out-dated plug-ins only resulted in the rather meaningless error message “Could not create directory”. So I started searching the web for possible solutions. I quickly found some posts explaining this issue to be a directory permission problem. Manually creating the /wp-content/upgrade directory and chmoding it as well as the plug-in directories to 777 should solve the problem. Unfortunately not for me. Therefore I rolled up my sleeves and started to debug WordPress…

    To cut a long story short, eventually I came across this PHP bug report #42739 mkdir doesn’t like a trailing slash when safe_mode is enabled and it turned out that this was the issue I was facing with on my hosting account too. The safe_mode option is enabled and WordPress tries to create directories that end with a slash (e.g. /htdocs/wp-content/upgrade/the-plugin/).

    After knowing the reason I could develop a workaround and finally got the one-click updater running. If you are facing the same issue you can try to use my patch too.

    1. Locate and open the file <wp_root>/wp_admin/includes/class-wp-filesystem-direct.php in an editor
    2. Search for “function mkdir
    3. Add the following statements to this method
      function mkdir($path,$chmod=false,$chown=false,$chgrp=false){
      	if( ! $chmod)
      		$chmod = $this->permission;
      	// workaround for starts here
      	if(ini_get('safe_mode') && substr($path, -1) == '/')
      		$path = substr($path, 0, -1);
      	// workaround for ends here
      	if( !@mkdir($path,$chmod) )
      		return false;
      	if( $chown )
      	if( $chgrp )
      	return true;
    4. Start one-click updating!

    Update 1:

    1. The patch also works for WordPress 2.5.1
    2. If applying this patch does not lead to success the problem may have a second cause. Therefore also check the permissions on the /wp-content/upgrade/ folder and it’s sub folders, e.g. chmod them to 777. If the upgrade directory does not exist at all it may be sufficient to create it manually.

    Update 2:

    1. In case the patch does not work check if you have the AskApache Password Protect plug-in installed.
    2. If so, try to deactivate this plug-in before you try to upgrade any other plug-in.

  • myPodder – a mobile podcatcher

    1 Star2 Stars3 Stars4 Stars5 Stars
    Posted on 20 April 2008 Sebastian Thomschke*/?> 1 comment

    Two weeks ago I started trying out podcasts seriously for the first time. So far I mainly tried the ones from a German news radio station ( I downloaded the audio files about topics I found interesting and listened to them while traveling to and from work. I really enjoyed it – especially because of the facts that I could now listen to talks and reports I am really interested in and I didn’t had to pay attention to when they are broadcasted. However I found it quite cumbersome to navigate through the radio station’s web page, to select each podcast separately, to download them and finally to transfer them to my neat Samsung T9.

    So I started looking for some tools that could simplify this process. I finally came across a handy software called myPodder provided for free by Podcast Ready. Podcast Ready provides an online catalog of available podcasts from different sources and to my surprise they also have that German radio station listed. The interesting thing about their software is the fact that you can directly install it onto your mobile audio player and have it launched automatically the moment it is connected to a computer. This means you can easily charge your player with new podcasts from any computer having an internet connection. Simply connect the player, wait for the program to launch, select some new podcasts and download them.
    Read the rest of this entry »

  • My favorite WordPress Plug-ins & Resources

    (2 votes) 1 Star2 Stars3 Stars4 Stars5 Stars
    Posted on 30 September 2007 Sebastian Thomschke*/?> 3 comments

    Now that I gained some experiences with WordPress, here comes a list of my favorite WordPress Plug-ins:

    Read the rest of this entry »