Apache 2 Tomcat 5 mod_jk on Debian 3.1 Integration
The whole tutorial is based on many tutorials, but I made a very simple one, with no virtual hosts.
The main source of info can be found here: http://www.howtoforge.com/apache2_tomcat5_mod_jk Installing Apache2 I followed this link: http://www.howtoforge.com/perfect_setup_debian_sarge_p5 Run Code:
apt-get install apache2 apache2-doc Code:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml Code:
DirectoryIndex index.html index.htm index.shtml index.cgi index.php index.php3 index.pl index.xhtml Code:
#application/x-httpd-php phtml pht php Code:
<IfModule mod_php4.c> Code:
Listen 80 Code:
a2enmod ssl Code:
/etc/init.d/apache2 restart Installing JDK (Java Development Kit) In order to run Tomcat, you will need to install JDK and set the JAVA_HOME environment variable to identify the location of the JDK environment on your system. I have chosen to use JDK 5.0. You can download JDK 5.0 at 1.http://java.sun.com/j2se/1.5.0/download.jsp. 2.Click on Download JDK 5.0 Update 6 to go to the download page. 3.Click Accept to accept the license agreement. 4.Next choose the Linux self-extracting file. This is the download for the self-extracting binary file rather than the rpm. 5.Download to your preferred download directory. Change to that directory and make it executable by executing the following command: Code:
chmod +x jdk-1_5_0_06-linux-i586.bin Code:
./jdk-1_5_0_06-linux-i586.bin Code:
mv jdk1.5.0_06 /usr/lib Code:
cd /usr/lib Code:
JAVA_HOME=/usr/lib/jdk Check to make sure JAVA_HOME is defined correctly by executing the command below. This should report the location of the Java SDK which should be /usr/lib/jdk. Code:
echo $JAVA_HOME In this section you will download and install Apache Tomcat 5.5.16. For this particular setup, there is no need to build the package from source, we will download the binary version. 1.Download the binary version to your preferred download directory from here: http://tomcat.apache.org/download-55.cgi. Choose the tar.gz from the core section for 5.5.16. 2.Now change to that directory and extract the files using the following command: Code:
cd /mydownloads Code:
tar xvzf apache-tomcat-5.5.16.tar.gz 3.Now move this directory to the location where it should be installed. Again, I chose /usr/lib/. Note that this location will be referred to as CATALINA_HOME in the Tomcat documentation. Code:
mv apache-tomcat-5.5.16 /usr/lib Code:
cd /usr/lib Code:
ln -s apache-tomcat-5.5.16 apache-tomcat You should now be able to start and stop Tomcat from the CATALINA_HOME/bin directory. If you are using another shell other than the bash shell you will nee to add sh to the beginning of the command. You should now be able to test that Tomcat is installed by starting it and opening your browser and entering http://localhost:8080 into your browser. Port 8080 is the default port for Tomcat and can be easily changed in the /usr/lib/apache-tomcat/conf/server.xml file. (We will work with this file later on.) If you plan to access this page remotely, be sure to forward the respective port to your server’s IP address within your router. You should now see the Tomcat welcome page that contains links to Tomcat documentation as well as sample JSP/Servlet scripts. Verify that Tomcat is running by executing some of the examples found on the welcome page. Code:
cd /usr/lib/apache-tomcat/bin Code:
./shutdown.sh In order to make the connection between Tomcat and Apache, we will need to download and install mod_jk connector. You will find that the Apache documentation recommends that you install the packaged version of mod_jk if it is available for your particular Linux distribution. Many outdated resources recommend installing the mod_jk2 connector, but I have found that it has been deprecated and although mod_jk was developed before mod_jk2, it is still fully supported and is very stable. Mike Millson gave some good reasoning behind using mod_jk for connecting Tomcat to Apache for Red Hat here: Integrating Tomcat and Apache on Red Hat Linux. 1. I chose to download the current source from the Apache archives: http://archive.apache.org/dist/jakar...rce/jk-1.2.15/. Download the jakarta-tomcat-connectors-1.2.15-src.tar.gz file to your /usr/src/ directory. 2.Change to the /usr/src directory. Code:
cd /usr/src Code:
tar xvzf jakarta-tomcat-connectors-1.2.15-src.tar.gz Code:
cd jakarta-tomcat-connectors-1.2.15-src/jk/native Code:
./buildconf.sh /usr/src/jakarta-tomcat-connectors-1.2.15-src/jk/native directory. 6.Execute the following command in order to configure mod_jk for your system. Important note: You will need to have apxs2 (APache eXtension tool) installed and configured with Apache. If you do not have it, as was my case, you can download and install the apache2-threaded-dev package (which replaced the former apache-dev package) from www.debian.org. At the time of this writing, the Debian package archive at www.debian.org was down and they referred me to their temporary site until they resolved their issues pdo.debian.net. I found the apache2-threaded-dev package and was able to install it successfully. Be sure to include the correct location apxs2 on your system in the path of the command. Code:
./configure --with-apxs=/usr/bin/apxs2 Code:
make Code:
cd apache-2.0 Configuring Tomcat and Apache Create the workers.properties file Important note: Be sure to make a backup copy of your config files before modifying. The workers.properties file contains the details about how each process is linked to Tomcat by defining workers that communicate through the ajpv13 protocol. Refer to the Workers HowTo for more detail. 1.First create the workers.properties file in your Apache2 root directory. touch /etc/apache2/workers.properties 2.Next, open the workers.properties file and add the following. You can find many other examples of the workers.properties file on the internet, but this is the one that I created and it seems to work fine with the other portions that have already been configured in this tutorial. Code:
workers.tomcat_home=/usr/lib/apache-tomcat 4.Now we need to open the /etc/apache2/apache2.conf file and add the following lines at the bottom. (httpd.conf is just for backward compatibility) Code:
LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so Now a final security point. We will create a group and user tomcat tomcat like that: Code:
groupadd tomcat Code:
chown -R tomcat.tomcat /usr/lib/apache-tomcat-5.5.16 Code:
passwd tomcat Then to start and stop the Tomcat server you should use the tomcat user. Code:
su - tomcat Code:
cd /usr/lib/apache-tomcat/bin Code:
./startup.sh Code:
/etc/init.d/apache2 restart You are done. Testing: In this test, we are directing all URLs that begin with "/jsp-examples" to Tomcat. In a real world situation, we might only direct JSPs or servlets to the JK worker. Make sure no other server is running on the default Tomcat ports of 8005, 8009 and 8080. Make sure no other server is running on the Apache port, which is normally 8080 or 80. Start Tomcat first: Always start Tomcat first and then start Apache. If you have to bounce Tomcat, remember to take down Apache first and restart it after Tomcat restarts. Start Apache: Point your browser to http://localhost and verify that you get the default Apache page. Substitute "localhost" for the actual machine name/IP if necessary. Point your browser to http://localhost:8080 and verify that you get the default Tomcat page. Point your browser to http://localhost/jsp-examples/ and verify that you get the index page for the Tomcat examples. This will be served by Apache and will indicate that you have completed your integration of Apache and Tomcat successfully. Reference and paths: Tomcat configuration file: /usr/lib/apache-tomcat/conf/server.xml Tomcat stop and start: Code:
cd /usr/lib/apache-tomcat/bin /usr/lib/apache2/modules Apache2 configuration files: /etc/apache2/workers.properties /etc/apache2/apache2.conf /etc/apache2/httpd.conf Apache2 start, stop and restart commands: Code:
/etc/init.d/apache2 restart Of course if you find any errors, please do post them in here so that I will update the tutorial. Please also make a vote above to check how useful this tutorial was for you. |
After nearly an entire day of increasing frustration I could not get tomcat working, finally I followed your guide here and BAM! it works. Thanks a lot.
|
Unless tomcat5 is needed i think it could have been simpler to provide a tutorial using apt(almost only)
* configure apt to install blackdown jdk for example(if blackdown jdk is the only jvm then the path is already configured, no need to use the PATH variable etc.) * i don't think php or php apache module is needed * the jakarta connector for tomcat is also available using apt i think * the rest is straightforward I configured many times apache and tomcat and always found it pretty simple. Locate the documentation, apply what you read to the distribution you run as easily as possible(ie use apt as much as possible). Brief, you could provide a debian way and a hardcore way without apt(wget file.tar.gz, tar zxvf file.tar.gz, ./configure, make install, etc.) However, it is a pretty good tutorial for anyone "really" familiar with linux. |
I tried installing via apt. It didn't work well for me. Not that it wouldn't be easier via apt perhaps, but I could not find anything to tell me how to do it. I installed tomcat4 and jk2 from the repository. Eventually I got tomcat running, but I couldn't get the servlets to work. In other owrds it would be nice to have a tutorial that covered installing via apt, but as it is this one made my day.
One thing I still do not get is the book I have says that servlets should go in webapps/ROOT/WEB-INF/classes and that the url should be something/servlet/HelloWorld for example. Is this old information or how do I set it up for this to work? update: OK, I found the answer at http://tomcat.apache.org/tomcat-5.0-...dev/index.html |
Very Very Helpful Thank You
|
Hi mrcheeks,
You could post a thread with your apt installation ... That would help us all since we could not make it work. Waiting for your post impatiently. |
Hello!
I tried it but i am getting the following errors, can't figure out what's the problem.Can any one help me with these problems? The mod_jk.log file says: Code:
[jk_ajp_common.c (1477)]: Error connecting to tomcat. Tomcat is probably not started or is listening on the wrong port. worker=default failed errno = 13 Code:
[Tue Jul 18 14:09:19 2006] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) |
Hello,
1) What Linux distribution are you using? 2) Is your apache working alone? 3) Is you tomcat working alone? I see LDAP errors, what are you trying to do? My manual is not about LDAP ... And I see a Fedora error too. My manual is for Debian. |
Hi,
Thanks a lot for the quick reply.I am using FedoraCore4 and tomcat is working as standalone. Don't know about apache?.Don't have any idea of it? I am trying to execute JSP with apache.The software versions are the same. Does distributions really make a difference,when softwares and their versions are same? |
Well my manual is using many apt-get install for packages which might not be available for Fedora and configuration files vary a lot in location and the way you should execute the commands.
This link might help you more: http://www.fedoraforum.org/forum/arc...p/t-28392.html |
I have tried it and its not working for me.Infact i've tried many,
but not getting the solution. Thanks a lot :) for your help. Regards! |
could not find /usr/bin/apxs2
when i try to install and configur mod_jk and run
./configure --with-apxs=/usr/bin/apxs2 after a while i get following error: checking for perl... /usr/bin/perl could not find /usr/bin/apxs2 configure: error: You must specify a valid --with-apxs path but I see apxs2 and it located /usr/bin/ but i dont know why it can not find it. when |
Can you please do that:
#ls -lrt /usr/bin |
Quote:
yes I do and it generates many thinks, |
Post the output in here.
|
All times are GMT -5. The time now is 10:22 AM. |