apache+tomcat+jk+php配置手册

    apache+tomcat+jk+php配置手册
    
一.前言
 因为业务需要,必须将apache与tomcat进行整合,网上有很多文章谈到这个配置过程,
但有的版本杂乱,有的语焉不详。本文是以亲身实践为基础写的一篇配置手册。 
 
   
二.软硬件环境
 (1) 平台
  Windows 2K/XP/2003
 (2) 软件包
  j2sdk1.4.2_04    
  apache_2.0.50-win32-x86-no_ssl.msi
  jakarta-tomcat-5.0.28.exe
   mod_jk-1.2.8-apache-2.0.52.so 
   php-4.3.10-Win32.zip

三.安装步骤
 (1)     Jdk安装
  主要是安装好后配置环境变量:
  PATH:加入C:/Sun/AppServer/jdk/bin
  JAVA_HOME:C:/Sun/AppServer/jdk
  CLASSPATH:.;C:/Sun/AppServer/jdk/jre/lib/rt.jar;C:/Sun/AppServer/jdk/lib/tools.jar
  
  
 (2)  Apache安装
  直接点安装包安装即可。
  检验成功:
  将文件名 c:/apache/htdocs/index.html.en 改为c:/apache/htdocs/index.html
  在网页上输入http://localhost/,显示APACHE欢迎页,说明apache安装成功
 
 (3) php的安装
     a) Extract the distribution file into C:/PHP.  
  b) Add “C:/php” to PATH
  c) The next step is to set up a valid configuration file for PHP,
      php.ini. There are two ini files distributed in the zip file,
     php.ini-dist and php.ini-recommended. We advise you to use
      php.ini-recommended, because we optimized the default settings in this
      file for performance, and security.
      If you are running Apache 2, the simpler option is to use the
        PHPIniDir directive (read the installation on Apache 2 page),
        otherwise your best option is to set the PHPRC environment variable.
                d)    The following steps are optional:

       * Edit your new php.ini file. If you plan to use OmniHTTPd, do not
         follow the next step. Set the doc_root to point to your web
         servers document_root. For example:
  
  doc_root = c:/inetpub       // for IIS/PWS
  
  doc_root = c:/apache/htdocs // for Apache
                 
                5)
  php有两种和apache一起运行的方式,一种
  是CGI,一种的mod_so.
  CGI方式下对apache的配置文件这样修改:
  Example 2-5. PHP and Apache 2.0 as CGI
  ScriptAlias /php/ "c:/php/"
  AddType application/x-httpd-php .php
  # For PHP 4
  Action application/x-httpd-php "/php/php.exe"
  # For PHP 5
  Action application/x-httpd-php "/php/php-cgi.exe"
  
  Warning
  
  By using the CGI setup, your server is open to several possible
  attacks. Please read our CGI security section to learn how to defend
  yourself from those attacks.
       ___________________________
  mod_so方式下这样修改:
     Example 2-6. PHP and Apache 2.0 as Module
  # For PHP 4 do something like this:
  LoadModule php4_module "c:/php/sapi/php4apache2.dll"
  AddType application/x-httpd-php .php
  
  # For PHP 5 do something like this:
  LoadModule php5_module "c:/php/php5apache2.dll"
  AddType application/x-httpd-php .php
  
  # configure the path to php.ini
  PHPIniDir "C:/php"
  
       Note: Remember to substitute the c:/php/ for your actual path to
       PHP in the above examples. Take care to use either php4apache2.dll
       or php5apache2.dll in your LoadModule directive and not
       php4apache.dll or php5apache.dll as the latter ones are designed to
       run with Apache 1.3.x.
  
     Warning
  
     Don't mix up your installation with DLL files from different PHP
     versions. You have the only choice to use the DLL's and extensions
     that ship with your downloaded PHP version.

  
  
  在C:/php里面有份安装文档,对整个安装和配置过程讲的非常仔细,可以直接参考.
  编写测试文件 info.php (拷贝到目录 c:/apache/htdocs/ 下)
  文件内容:(就一行)
  
  访问: http://localhost/info.php 或 http://root.dev/info.php
  如果看到PHP的欢迎测试页面,说明安装成功!
  到目前为止,你的系统已经可以运行PHP程序了!
  
 (4)     jakarta-tomcat-5.0.28.exe
  直接点安装包安装即可。 
 
 (5) mod_jk-1.2.8-apache-2.0.52.so安装 
  这里是重点了:如何讲apache与tomcat进行整合。
  将mod_jk-1.2.8-apache-2.0.52.so修改为mod_jk.so,然后拷贝到apache的modules目录。
  修改apache的配置文件httpd.conf,加入如下配置文本:
  
  LoadModule jk_module modules/mod_jk.so
  JkWorkersFile "C:/Program Files/Apache Software Foundation/Tomcat 5.0/conf/worker.properties"
  JkLogFile logs/mod_jk.log
  JkLogLevel info
  
  JkMount /BaseServlet worker1 
  JkMount /Servlet/* worker1 
  JkMount /ProductUploadServlet worker1 
  JkMount /upload worker1 
  JkMount /test worker1 
  JkMount /jive/* worker1 
  JkMount /*.jsp worker1 
  JkMount /*.do worker1 

  注意,Jkmount定义的是配置匹配部分,告诉apache哪些请求需要发给Tomcat去处理,
  JkMount所引用的worker的名称必须是在work.list定义过的(下面的workers.properties文件)
  在C:/Program Files/Apache Software Foundation/Tomcat 5.0/conf加入文件worker.properties
  文件内容如下:
  worker.list=worker1
  # Set properties for worker1 (ajp13)
  worker.worker1.type=ajp13
  worker.worker1.host=127.0.0.1
  worker.worker1.port=8009
  worker.worker1.lbfactor=50
  worker.worker1.cachesize=10
  worker.worker1.cache_timeout=600
  worker.worker1.socket_keepalive=1
  worker.worker1.socket_timeout=300
  
  最后检查C:/Program Files/Apache Software Foundation/Tomcat 5.0/conf/server.xml里
  面8009端口是否被注释掉,如果是被注释掉的,把注释去掉


 (6) 如何判断各个软件包是否安装成功?
 
  测试:大家首先启动Apache,然后在浏览器里输入http://localhost,如果能看
  到Apache的欢迎页面,那么恭喜您,第一步成功了。然后回到Tomca目录下
  运行startup.bat启动Tomcat,再打开浏览器输入:http://localhost:8080/
  如果看到可爱的Tomcat,那么恭喜您,Tomcat也没有问题,最后最重要的是
  Apache下可以解释jsp和Servlet,把下面的代码copy到文本编辑器中命名为
  hello.jsp,
  内容如下:
  <%@ page contentType="text/html;charset=gb2312"%>
  
  
  <%String str="Hello World!";%>
  <%str=str+"你好";%>
  <%=str%>
  
  
  
  将它保存到C://Apache Tomcat 4.0//webapps//ROOT下,然后在浏览器里输入
  http://localhost/hello.jsp。如果看到了Hello,那么您的确成功了。
    

四.jive安装
 这里使用的是J道提供的jive2.5版本,安装过程中发生了一些问题,解决过程如下:
 1.在输入jdbc连接字串的时候,使用如下的字串以支持中文:
 jdbc:mysql://127.0.0.1/Jive?useUnicode=true&characterEncoding=UTF-8
 如果只使用jdbc:mysql://localhost/jive,那么论坛将无法支持中文
 2.post.jsp文件有错误,需要将myEnv.getForumFactory()改为forumFactory.

你可能感兴趣的:(apache+tomcat+jk+php配置手册)