新一篇Apache2与Tomcat7整合

来源:互联网 发布:mysql 图形化工具 mac 编辑:程序博客网 时间:2024/06/07 04:44

注意:本文出自 “阿飞”的博客 ,如果要转载本文章,请与作者联系!
并注明来源: http://blog.csdn.net/faye0412/article/details/8031407


1.安装httpd,JDK,Tomcat7
过程略

2. 安装httpd扩展
yum -y install httpd-devel

PS:
LINUX平台下,默认安装的apache httpd服务是没有安装httpd的开发包,所以,大家在查找apxs扩展工具的时候,经常找不到默认的安装位置。比如,在编译安装PHP的时候,可能 需要指定'--with-apxs=/path/sbin/apxs',但是,往往会编译错误,并提示找不到apxs,这时候的解决办法如下:
1. 查找系统中是否安装了apxs apache扩展工具:
如上,返回的结果则说明系统并没有安装apxs扩展工具。
正常安装的返回结果如 下:
[root@localhost bin]# whereis apxs
apxs: /usr/sbin/apxs /usr/share/man/man8/apxs.8.gz

3.安装tomcat-connectors
tar zxvf tomcat-connectors-1.2.37-src.tar.gz
cd tomcat-connectors-1.2.37-src/native/
./configure --with-apxs=./configure --with-apxs=/usr/sbin/apxs
make && make install


4. 配置httpd.conf 文件

#vi /etc/httpd/conf/httpd.conf

添加

<IfModule jk_module>
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
</IfModule>

Include /etc/httpd/conf/mod_jk.conf

LoadModule jk_module modules/mod_jk.so


5.创建并配置workers.properties文件

#vi /etc/httpd/conf/workers.properties

worker.list=webserver,jkstatus
worker.ajp13w.type=ajp13
worker.ajp13w.host=localhost
worker.ajp13w.port=8009
worker.webserver.type=lb
worker.webserver.balance_workers=ajp13w

worker.jkstatus.type=status


6.创建并配置uriworkermap.properties

#vi /etc/httpd/conf/uriworkermap.properties

/admin/*=webserver
/manager/*=webserver
/jsp-examples/*=webserver
/servlets-examples/*=webserver
/examples/*=webserver
/*.jsp=webserver
!/servlets-examples/*.jpeg=webserver

/jkmanager=jkstatus


7.编辑server.xml文件

vi /usr/local/tomcat/conf/server.xml


在这个位置修改


<Host name="localhost"  appBase="webapps" 
            unpackWARs="true" autoDeploy="true">

修改为:

<Host name="localhost"  appBase="webapps" 
            unpackWARs="true" autoDeploy="true" 
            xmlValidation="false" xmlNamespaceAware="false"> 
<Context path="" docBase="/var/www/html" debug="0"/>



8.在/var/www/html下创建测试文件jsptest/test.jsp

#vi /var/www/html/jsptest/test.jsp

<% 
    System.out.println( "Evaluating date now" ); 
    java.util.Date date = new java.util.Date(); 
%> 
Hello!  The time is now <%= date %>


9.启动tomcat 和httpd 服务,测试

访问http://192.168.1.10/jsptest/test.jsp 时输出当前日期时间:
Hello! The time is now Sat Sep 29 10:28:04 SGT 2012


10.其他方式整合可以参考:

http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/


11.测试错误解决:

测试时发现不能解析php,具体表现为页面空白,但可以解析html和jsp,但是phpinfo无法显示的错误
解决:<?php
phpinfo();
?>
?后少加了后缀php。这是php.ini没有设置好的原因。

在php.ini文件中将:
short_open_tag = Off
把这个设置为ON即可






原创粉丝点击