Install Movable Type Under Apache Tomcat

I haven’t done a lot of work with Apache Tomcat previously, so when someone asked if they could install Movable Type, I had to do a bit of digging to see if it was possible. The answer is actually yes – but it’s not the most intuitive installation. Most steps are fairly simple, but making the pieces work can be challenging.

Getting Perl up and running under Tomcat isn’t difficult – just dropping the files into a directory seems to make them work. But to make Movable Type work, you need more than just Perl – you need MySQL. That’s where the trouble comes in and things get a little dicey.

First off, to make MySQL work correctly, you need to set up the CGI Servlet. And to do this, you need to update your web.xml file. Make sure that you back up this file before you change it, because if you don’t and you break something, your whole server will go down and go down quickly. Once you’ve backed it up, load the file in your favorite text editor.

Then, search for cgi. You’ll find that Tomcat has a CGI Servlet already set up for you – you just need to uncomment it. At the top you have a large block of comments explaining all the variables and then you have the code itself. Leave the comments at the top, just in case you need to change something later, then uncomment the servlet itself. The default container looks like this:

 <servlet>
  <servlet-name>cgi</servlet-name>
  <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
  <init-param>
   <param-name>debug</param-name>
   <param-value>6</param-value>
  </init-param>
  <init-param>
   <param-name>cgiPathPrefix</param-name>
   <param-value>WEB-INF/cgi</param-value>
  </init-param>
  <load-on-startup>5</load-on-startup>
 </servlet>

Now, the default doesn’t quite work for what we need. You’ll have to add one other parameter in order to make MySQL work correctly with Perl. This took me quite some time to track down, so I hope it saves you some time. Add one more parameter (shown in bold below):

 <servlet>
  <servlet-name>cgi</servlet-name>
  <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
  <init-param>
   <param-name>debug</param-name>
   <param-value>6</param-value>
  </init-param>
  <init-param>
   <param-name>cgiPathPrefix</param-name>
   <param-value>WEB-INF/cgi</param-value>
  </init-param>
  <init-param>
   <param-name>passShellEnvironment</param-name>
   <param-value>true</param-value>
  </init-param>
  <load-on-startup>5</load-on-startup>
 </servlet>

By adding the passShellEnvironment parameter – and setting the value to true, where the default is false – it will allow for Perl to interact with MySQL under the CGI Servlet. This might be the only thing you need to do in order to get Movable Type working, but I added one other thing that made the installation look a little more like a standard setup.

If you don’t add this parameter, you will end up with a very unhelpful message that tells you that it Can’t create TCP/IP socket (10106). The only message related to this in the forums or online is that you should set the DBSocket configuration directive. Unfortunately under Windows there is no socket, so that’s not going to help. Just add this line and you’ll be set.

Now search the web.xml file for cgi-bin. This takes you a bit farther down the file and shows you the mapping of the CGI Gateway Servlet. This allows you to place the Movable Type files in a location that is not web-accessible, but access them as if they were. Simply uncomment this section to activate:

 <servlet-mapping>
  <servlet-name>cgi</servlet-name>
  <url-pattern>/cgi-bin/*</url-pattern>
 </servlet-mapping>

What this means is that if someone requests something in /cgi-bin/ it will be served from cgi. Now you just need to make sure that MT is in cgi and you’ll be set. Take the Movable Type installation and load it into a directory called cgi under the WEB-INF directory. The WEB-INF directory is a special protected location that is not normally accessible from the outside. By placing the data here, you are required to set up the servlet-mapping function above.

Because of the earlier parameter in the Servlet, where we set the cgiPathPrefix, I am fairly certain that this step is required. But feel free to move things around. Personally, I prefer to create an mt directory in the cgi directory – so it is actually WEB-INF/cgi/mt – and it works great. This way, if you have more than one application there, you can segregate them by directory.

Since the WEB-INF directory is not accessible, you will need to move the mt-static folder into a directory that is available to the outside world (and make changes to your configuration file – we will do that in a minute). I just put it in the root.

Finally, in your Movable Type configuration file, you just need to set your paths correctly. These are fairly standard, but I want to be thorough, so here are the settings you need:

CGIPath /cgi-bin/mt/
StaticWebPath /mt-static/

I use relative paths here because this particular job was done on a development server, and that way when it is put into production, they don’t need to change anything. If you like, you can make these paths absolute with a full URL to each.

The last step is to restart your Tomcat server, using your monitor in the taskbar or the services applet. You could also reboot the server, but that would take a lot longer (and take your site down for a while). When it comes back up, you should be ready to log in to Movable Type!


Posted

in

Comments

2 responses to “Install Movable Type Under Apache Tomcat”

  1. Darren Avatar
    Darren

    Here we are four and a half years later and your post just helped another MT user. Thanks!

  2. Shrini Avatar
    Shrini

    thanks a bunch Chad; was trying to fix this weird Can’t create TCP/IP connection for a long time. passShellEnvironment rocks!