Home >Backend Development >PHP Tutorial > PHP跟Tomcat整合

PHP跟Tomcat整合

WBOY
WBOYOriginal
2016-06-13 13:08:52845browse

PHP和Tomcat整合

我的软件如下:

Apache2.2 ?目录:C:\Program Files (x86)\Apache Software Foundation\Apache2.2

Tomcat 5.5 目录:D:\apache-tomcat-5.5.25

PHP 目录:D:\DEV\php-5.2.13-Win32-VC6-x86

MySql Server5.2 目录:C:\Program Files (x86)\MySQL\MySQL Server 5.2

JK插件:mod_jk-1.2.28-httpd-2.2.3.so

?

需要做如下设置:

1. 安装Apache2.2,过程中让你选择域名和端口,我写的是www.seya.com,端口:80. 邮箱写个自己的好了:seyason@gmail.com.这些都在配置文件httpd.conf里,后面也可以自己改的。

?

2. 安装java JDK和设置Tomcat 环境变量,CATALINA_HOME和CATALINA_BASE设置到tomcat的根目录就行了,保证在tomcat下的bin目录下运行catalina start命令能跑起来。

?

3. 安装MySql Server5.2 都按默认配置好了,一路Next. 设置root账号的密码,比如是111111.

?

4. 配置PHP服务,让它能同时提供PHP和JSP的服务。

1》将php安装目录下的php.ini-dist文件改名为php.ini, 去掉这几行前面的分号(取消注释)

? extension=php_mbstring.dll
? extension=php_dbase.dll
? extension=php_gd2.dll
? extension=php_mysql.dll

并改extension_dir =”extension_dir = "D:/DEV/php-5.2.13-Win32-VC6-x86/ext/“ 以上那几个文件就在这个目录下。

2》配置Apache,修改C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf文件

修改 DocumentRoot "D:/DEV/php-5.2.13-Win32-VC6-x86/webroot/"

修改

在ScriptAlias /cgi-bin/ "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin/"下面增加几行,使其支持PHP服务:

??? ScriptAlias???????????? /php/? "D:/DEV/php-5.2.13-Win32-VC6-x86/"
??? addtype??????????? application/x-httpd-php .php
??? action????????? application/x-httpd-php "/php/php.exe"

3》加载PHP模块和JK模块

?? LoadModule php5_module "D:/DEV/php-5.2.13-Win32-VC6-x86/php5apache2_2.dll"
?? AddHandler application/x-httpd-php .php

?? # configure the path to php.ini
?? PHPIniDir "D:/DEV/php-5.2.13-Win32-VC6-x86"

?? LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so

4》配置和Tomcat的集成

? 在D:\DEV\php-5.2.13-Win32-VC6-x86下新建目录ConnApaTom,在其下新建文件workers.properties, 内容如下:

? workers.tomcat_home=D:\apache-tomcat-5.5.25
workers.java_home=C:\Program Files (x86)\Java\jdk1.5.0_05
worker.list=ajp12, ajp13
worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
worker.ajp12.lbfactor=1
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp12, ajp13
worker.inprocess.type=jni
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar
worker.inprocess.cmd_line=start
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr

?

然后再修改C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf文件, 加这么几行:

JkWorkersFile "D:/DEV/php-5.2.13-Win32-VC6-x86/ConnApaTom/workers.properties"
JkMount /servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /*.do? ajp13

就是把.jsp, .do 和 /servlet的请求转到workers.properties中设置的路径去处理,也就是D:\apache-tomcat-5.5.25。 实现了将JSP整合到了PHP server下。
?

至此配置工作完成,重启Apache和Tomcat。把你的JSP项目,或者php项目放在D:\DEV\php-5.2.13-Win32-VC6-x86\webroot目录下,通过localhost:80端口都可以访问了。

?

?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn