Songsterq's Blog

CentOS + Tomcat + MySQL + Grails

Posted on: 08/12/2010

I need to configure a server to run my Grails application. Instead of jumping directly onto the production server, I decided to give it a try on VirtualBox first. Instead of LAMP, I used what I called a “LTMG” stack: Linux, Tomcat, MySQL, Grails. For the most part it’s straightforward, but there are a few tricks that took me some time to figure out.

1. CentOS

Very simple, download the ISO images and follow Section 2 of Blake’s CentOS LAMP Server Guide to get it installed and configured. I also get VirtualBox Additions installed so I don’t have to repeatedly press the right ctrl key to release my mouse pointer from the VM, instructions are available here.

2. JDK, JRE and Tomcat

I don’t like the OpenJDK now shipped standard in CentOS, so I installed the official version from Sun. Tomcat installation was also a breeze.

3. MySQL

This is where the fun begins. Section 3.4 of Blake’s CentOS LAMP Server Guide talks about installing MySQL on CentOS. However, I couldn’t get pass the step of importing the PGP key. “import read failed(-4)” is what I got. After searching around, it turned out the key provided here is missing the key ID. The complete key is on a mirror site. With the key successfully imported, everything went on smoothly. After installation is done, I created the database needed to run my grails app.

4. Grails

Don’t really need to do any installation for Grails. Just run “grails war” and deploy the resulting war file on Tomcat. However, when I try to run my app, unicode characters got saved as question marks. I re-created the database using UTF8 as default character set, the problem remained the same. This is weird because grails already has spring’s CharacterEncodingFilter built in. I built a test page to verify my form submits are indeed correctly encoded as UTF8, so the problem must be on the MySQL part. After ton’s of searching, I finally found the answer: I need to add “character-set-server = utf8” into /etc/my.cnf. (The file was created when configuring MySQL.) With this done, my app was finally 100% up and running!

Leave a comment