Monday, October 29, 2007

Leopard for the Web Developer - installing mod_jk

Today I was pleased to get a few comments from a fellow programmer anxious to set up his Mac so Apache could connect with Tomcat with the help of mod_jk. He came looking for info, found none, and kindly came back later to reveal his findings. Here's billo's instructions about how to install mod_jk on Mac OS X Leopard (for an intel Mac).



He explains in some pretty good detail why it fails out of the tar-box, so I won't go into it. However, what I will do is give you a line-by-line for how to make it work. I had to fill in a couple gaps after finding out what the problem was. Here's what you need to do.



1. Download and unpack the source of mod_jk (I installed version 1.2.25)



2. Make your way into the source directory (tomcat-connectors-[version]-src/native)


$ cd tomcat-connectors-1.2.25-src/native


3. Edit the apache-2.0/Makefile.apxs.in file with billo's fix. This is the solution that fixes the build. What you need to do is replace these lines:


mod_jk.la:
$(APXS) -c -o $@ -Wc,"${APXSCFLAGS} ${JK_INCL}" "${JAVA_INCL}" "${APXSLDFLAGS}" mod_jk.c ${APACHE_OBJECTS}

with these:


mod_jk.la:
$(APXS) -c -o $@ -Wc,"${APXSCFLAGS} -arch x86_64 ${JK_INCL}" "${JAVA_INCL}" "${APXSLDFLAGS} -arch x86_64 " mod_jk.c ${APACHE_OBJECTS}

The tab at the beginning of the $(APXS) line is very important! Don't remove it.



4. While you're in the [src]/native directory, configure the build files


$ ./configure --with-apxs=/usr/sbin/apxs


5. Change directory into apache-2.0 and get ready to build.


$ cd apache-2.0


6. Make the module using apxs as your compiler


$ make -f Makefile.apxs


7. Install the module


$ sudo make install


From there, you're on your own getting it configured for Apache. But the documentation for configuring mod_jk is  abundant.

25 comments:

Anonymous said...

You could also pass the arch with the CFLAGS option when you configure (./configure CFLAGS="-arch x86_64" ...)

Thanks for the post though, I was trying to compile with -arch i368 per http://developer.apple.com/documentation/MacOSX/Conceptual/universal_binary/universal_binary_compiling/chapter_2_section_7.html

Anonymous said...

Eric,
you're blog saved my weekend. I was struggling with restoring my web development environment after upgrading to Leopard. I use Java/JSP/Apache with a tunnel to our databases on a MacBook Pro. Even our "experts" didn't have a solution for me.

I can't thank you enough. Hey...I saw your other post on Social Networks. It was very insightful. I have been working on a social network for itunes users. www.sonicswap.com....send me email over there to dan at sonicswapDotCom. I would love to get in touch. It is good to hang with web developers who "get it"
Best regards,
Dan

Filippo di Pisa said...

Hi Eric,
I'm trying to follow your instruction but I have one problem:

It seems that the "make()" commands in doesn't exists.

filippo@f:/var/log $ make
-bash: make: command not found

Do you have any idea?

Eric said...

I think your problem might have to do with the need to install the developer tools that comes with Leopard.

Once you have the Developer Tools installed, make will be installed and you should be able to commence building the module.

Filippo di Pisa said...

I downloaded and reinstalle XCode 3.0 but they are still not there

if I go do /usr/bin/ make is non there and neither the c compiler

any idea?

Filippo di Pisa said...

Ok I've reinstalled xcode 3.0 and now are there.

Before I had 2.5.

Now I try to see if the connector works.

Thanks for everything your blog is very useful and nice.

Filippo di Pisa said...

I've got make and the other tools working but the module is still not working

Jan 17 17:50:10 f com.apple.launchd[1] (org.apache.httpd): Throttling respawn: Will start in 10 seconds
Jan 17 17:50:20 f org.apache.httpd[28225]: httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_jk.so into server: dlopen(/usr/libexec/apache2/mod_jk.so, 10): image not found
Jan 17 17:50:20 f com.apple.launchd[1] (org.apache.httpd[28225]): Exited with exit code: 1
Jan 17 17:50:20 f com.apple.launchd[1] (org.apache.httpd): Throttling respawn: Will start in 10 seconds


Do you have any idea?

Eric said...

It looks like you have a syntax error on your httpd.conf file where you are trying to load the new module. What I did is this.

1. Instead of editing the httpd.conf, I added an included conf file in /etc/apache2/other/ named "jk.conf". That file looks like:

######################
# jk configuration
######################

LoadModule jk_module libexec/apache2/mod_jk.so
JkWorkersFile /etc/apache2/other/jk-workers.properties
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log
JkLogLevel debug


Make sure to create the log file that you specify. An empty text file will do.

2. My simple workers file (/etc/apache2/other/jk-workers.properties) looks like:

worker.list=tomcat

# Define the worker for tomcat running on the computer
worker.tomcat.port=8009
worker.tomcat.host=127.0.0.1
worker.tomcat.type=ajp13

3. Make sure to add the relevant connection info to your conf - I use a virtualhost for this.

# Deny access to WEB-INF and META-INF
<Location "/WEB-INF/*">
Deny from all
</Location>

<Location "/META-INF/*">
Deny from all
</Location>

# connect .jsp to the mod_jk worker for tomcat to handle
#the worker should be the one named in the workers file. "tomcat" in this case
JkMount /*.jsp tomcat

Filippo di Pisa said...

mhh..I rebuilt everithing and I copied your shema, but it is still returning BAD ARCHITECTURE

Jan 17 19:00:08 f org.apache.httpd[28621]: httpd: Syntax error on line 520 of /private/etc/apache2/httpd.conf: Syntax error on line 5 of /private/etc/apache2/other/jk.conf: Cannot load /usr/libexec/apache2/mod_jk.so into server: dlopen(/usr/libexec/apache2/mod_jk.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/mod_jk.so: mach-o, but wrong architecture

Any Idea?

Eric said...

I'm at a loss.

However, here are some things that I might check out.

1. The steps here are for version 1.2.25. The latest is 1.2.26. I wonder if this fix doesn't work for the latest version?

2. Check permissions. Whenever things don't work when they should for me, half the time it's a permissions issue.

3. I've had problems with the module when I neglected to specify a log file for mod_jk, or if the log file doesn't exist.

I have a feeling that the above suggestions may not help though. Let me know what you find out when you get it to work!

Filippo di Pisa said...

Many thanks.

However the link to download the .25 version is broken

http://tomcat.apache.org/connectors-doc/

can you publish your src and binary module please?

Eric said...

It looks like I must have gotten rid of the source I had when I built 1.2.25. I don't have the time to provide a link to the binary at the moment, but I tried building version 1.2.26, and it worked.

The important part is making sure you're in the right directory (tomcat-connectors-1.2.26-src/native/apache-2.0), and building with the Makefile.apxs

make -f Makefile.apxs

Invoking make from the native/ directory caused the same architecture problem for me as you mention.

Russ said...

Thanks a bunch for this nugget. I just got a MacBook Pro, and after using the binary lib from Apache unsuccessfully, a quick Google search brought me here.

20 minutes later - I'm back in business!!

Thanks again :)

Russ
Ontario, Canada

Anonymous said...

I was successful in everything and then when I added this to the httd.conf apache no longer started and there were no errors. Any ideas?

LoadModule jk_module /usr/libexec/apache2/mod_jk.so
JkWorkersFile /etc/apache2/workers.properties
JkShmFile /var/log/apache2/mod_jk.shm
JkLogFile /var/log/apache2/mod_jk.log

Eric said...

@Anonymous It sounds like it could be a couple things. The first thing to do is to open /Applications/Utilities/Console.app and see what kind of messages you get when you restart apache. I'm thinking that it could be a couple things.

1. The original problem -- bad architecture error. To fix, follow the source code modification instructions

2. Maybe your log file for mod_jk doesn't exist. Make sure to create the log file that you specify. An empty text file will do.

3. Check the syntax of your workers.properties file

Anonymous said...

Getting this error, though the file, mod_jk.so is in the correct place ...

5/1/08 11:30:22 AM org.apache.httpd[44862] httpd: Syntax error on line 501 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_jk.so into server: dlopen(/usr/libexec/apache2/mod_jk.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/mod_jk.so: mach-o, but wrong architecture

It mentions wrong Architecture.

Anonymous said...

Ignore my previous comment. Resolved by rebuilding one more time.

Eric said...

@anonymous

Looks like you have the module built and in the right place. However, the error your getting is what you get when the module is not built correctly. The instructions above should be good. I've checked them a couple times. Here are some details that might have slipped under the radar

1. Make sure to cd into the "native" directory when you do your configure and make. The build will seem like it goes ok if you're not in the "native" directory, but you get the error you mentioned

2. When editing the the Makefile.apxs.in file, make sure there's a tab at the beginning of the $(APXS) line

All of these details are outlined in the instructions above. So, basically, try starting over and following closely :-) Let me know how it goes.

Unknown said...

I have followed the above instructions exactly. Unfortunately, I am still getting:

httpd: Syntax error on line 488 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_jk.so into server: dlopen(/usr/libexec/apache2/mod_jk.so, 10): no suitable image found. Did find:\n\t/usr/libexec/apache2/mod_jk.so: mach-o, but wrong architecture

Has anybody else had similar problem even after making the above changes to the Makefile?

asac.cat said...

Many thanks for the post. billo's post was basically right, but he skipped over some details that were obvious to him.

MarkB said...

Eric,

I had difficulty configuring Apache with Tomcat on OSX Leopard myself and mentioned your post here:

http://happyworm.com/blog/2009/04/06/configuring-apache-with-tomcat-on-osx-leopard/

Cheers

MarkB

Anonymous said...

Eric,

I have my apache2 built and installed in /usr/local/apache2. After I build the mod_jk, I got the following error starting hpptd:

API module structure 'jk_module' in file /usr/local/apache2/modules/mod_jk.so is garbled - expected signature 41503230 but saw 41503232 - perhaps this is not an Apache module DSO, or was compiled for a different Apache version?

I noticed that the build is using -I/usr/include/apache2 instead -I/usr/local/apache2/include even I had APACHE_HOME setup.

Is this the root cause for my problem? Any idea how to fix it?

Thanks,

Clifford

macbook 13 said...

Thanks for the blog, very helpful information!

Unknown said...

this is an error i got. i have snow leopard, and i have been pulling my hair out, because of this problem.

httpd: Syntax error on line 467 of /etc/httpd/httpd.conf: Syntax error on line 4 of /usr/local/Tomcat/tomcat6/conf/auto/mod_jk.conf: Cannot load /usr/libexec/apache2/mod_jk.so into server: dlopen(/usr/libexec/apache2/mod_jk.so, 10): Symbol not found: _apr_stat$INODE64\n Referenced from: /usr/libexec/apache2/mod_jk.so\n Expected in: flat namespace\n in /usr/libexec/apache2/mod_jk.so

Anonymous said...

same issue...
Expected in: flat namespace\n in /usr/local/apache2/modules/mod_jk.so