apache+tomcat+php 整合与虚拟主机的配置
一.整合apache+tomcat+php
1》下载需要的软件:
Apache : apache_2.0.59-win32-x86-no_ssl.msi http://httpd.apache.org/
Tomcat : apache-tomcat-5.5.23.exe http://tomcat.apache.org/
Php : php-5.2.4-Win32.zip http://www.php.net
Mysql : mysql-5.0.45-win32.zip http://www.mysql.org
JDK : jdk-5-windows-i586.exe http://java.sun.com
JK插件 : mod_jk-apache-2.0.59.so http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.23/mod_jk-apache-2.0.59.so
Apache : apache_2.0.59-win32-x86-no_ssl.msi http://httpd.apache.org/
Tomcat : apache-tomcat-5.5.23.exe http://tomcat.apache.org/
Php : php-5.2.4-Win32.zip http://www.php.net
Mysql : mysql-5.0.45-win32.zip http://www.mysql.org
JDK : jdk-5-windows-i586.exe http://java.sun.com
JK插件 : mod_jk-apache-2.0.59.so http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.23/mod_jk-apache-2.0.59.so
2》安装软件
<1>安装Apache
在安装的过程中将会出现叫你填服务器的地址
我是这样写的:
127.0.0.1 或者localhost 或者是真实的ip地址或域名
127.0.0.1
your@yahoo.com 也就是你的油箱
我的Apache的安装目录是:D:\root\Apache2
<2>安装JDK环境
我的JDK的安装目录是:C:\jdk1.5.0
并增加JAVA_HOME和PATH变量
分别是:JAVA_HOME=C:\jdk1.5.0
PATH=%JAVA_HOME%\bin
<1>安装Apache
在安装的过程中将会出现叫你填服务器的地址
我是这样写的:
127.0.0.1 或者localhost 或者是真实的ip地址或域名
127.0.0.1
your@yahoo.com 也就是你的油箱
我的Apache的安装目录是:D:\root\Apache2
<2>安装JDK环境
我的JDK的安装目录是:C:\jdk1.5.0
并增加JAVA_HOME和PATH变量
分别是:JAVA_HOME=C:\jdk1.5.0
PATH=%JAVA_HOME%\bin
<3>安装Tomcat
Tomcat我采用的是默认安装
安装目录是:D:\root\Tomcat 5.5
端口:8080
<4>安装Mysql数据库
安装密码是:admin
数据库编码是:gbk
安装的目录是:D:\root\Tomcat 5.5
<5>安装php
解压php-5.2.4-Win32.zip到目录:D:\root\php
3》配置服务器,使能够提供jsp,php服务
<1>配置php
将php安装目录下的php.ini-dist文件改名为php.ini
修改办法:将扩展加入文件当中
并将:
extension=php_mbstring.dll
extension=php_dbase.dll
extension=php_gd2.dll
extension=php_mysql.dll
这些扩展前面的分号去掉
我做的修改是:
extension_dir = "d:/root/php/ext/"
extension=php_mbstring.dll
extension=php_dbase.dll
extension=php_gd2.dll
extension=php_mysql.dll
<1>配置php
将php安装目录下的php.ini-dist文件改名为php.ini
修改办法:将扩展加入文件当中
并将:
extension=php_mbstring.dll
extension=php_dbase.dll
extension=php_gd2.dll
extension=php_mysql.dll
这些扩展前面的分号去掉
我做的修改是:
extension_dir = "d:/root/php/ext/"
extension=php_mbstring.dll
extension=php_dbase.dll
extension=php_gd2.dll
extension=php_mysql.dll
<2>配置Apache
将JK插件拷贝到D:\root\Apache2\modules目录中,它的作用是将jsp请求转发给Tomcat
修改http.conf 文件在D:\root\Apache2\conf目录中
web服务的目录D:\root\webroot
将JK插件拷贝到D:\root\Apache2\modules目录中,它的作用是将jsp请求转发给Tomcat
修改http.conf 文件在D:\root\Apache2\conf目录中
web服务的目录D:\root\webroot
主要修改:
1:修改DocumentRoot
改后的值:DocumentRoot "D:/root/webroot"
2:修改Directory
改后的值:<Directory "D:/root/webroot">
3:增加php服务功能
在ScriptAlias下面加上:
1:修改DocumentRoot
改后的值:DocumentRoot "D:/root/webroot"
2:修改Directory
改后的值:<Directory "D:/root/webroot">
3:增加php服务功能
在ScriptAlias下面加上:
ScriptAlias /cgi-bin/ "D:/root/Apache2/cgi-bin/"
ScriptAlias /php/ "d:/root/php/"
addtype application/x-httpd-php .php
action application/x-httpd-php "/php/php.exe"
4:加载模块
在Dynamic Shared Object (DSO) Support下面加入:
LoadModule php5_module "d:/root/php/php5apache2.dll"
LoadModule jk_module modules/mod_jk-apache-2.0.59.so
加载的模块分别是php模块和jk模块
ScriptAlias /php/ "d:/root/php/"
addtype application/x-httpd-php .php
action application/x-httpd-php "/php/php.exe"
4:加载模块
在Dynamic Shared Object (DSO) Support下面加入:
LoadModule php5_module "d:/root/php/php5apache2.dll"
LoadModule jk_module modules/mod_jk-apache-2.0.59.so
加载的模块分别是php模块和jk模块
5:增加tomcat转发配置
在文件结尾加入:
JkWorkersFile "D:\root\ConnApaTom\workers.properties"
JkMount /servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /*.do ajp13
保存http.conf文件即可
6:配置和Tomcat的集成
新建ConnApaTom目录:目录地址是:
D:\root\ConnApaTom
将写好的workers.properties文件保存到该目录中
文件内容是:
workers.tomcat_home=D:\root\Tomcat 5.5
workers.java_home=C:\jdk1.5.0
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
修改Tomcat的配置文件:server.xml
在文件结尾加入:
JkWorkersFile "D:\root\ConnApaTom\workers.properties"
JkMount /servlet/* ajp13
JkMount /*.jsp ajp13
JkMount /*.do ajp13
保存http.conf文件即可
6:配置和Tomcat的集成
新建ConnApaTom目录:目录地址是:
D:\root\ConnApaTom
将写好的workers.properties文件保存到该目录中
文件内容是:
workers.tomcat_home=D:\root\Tomcat 5.5
workers.java_home=C:\jdk1.5.0
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
修改Tomcat的配置文件:server.xml
<Host name="localhost" appBase="D:\root\webroot"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
保存即可
在D:\root\webroot目录添加.html .jsp .php文件便可运行.
保存即可
在D:\root\webroot目录添加.html .jsp .php文件便可运行.
jsp的话还是要放入D:\root\webroot\root\*.jsp这样才能在http://localhost/*.jsp显示出来
二.虚拟主机的配置
1>.修改C:\WINDOWS\system32\drivers\etc\hosts文件
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
2>.修改D:\root\Apache2\conf\http.conf 在文件尾部加入:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin admin@aaa.com
DocumentRoot "D:/root/webroot/aaa"
ServerName www.aaa.com
ServerAlias *.aaa.com
DirectoryIndex index.jsp index.php index.htm index.html
ErrorLog logs/aaa.example.com-error_log
CustomLog logs/aaa.example.com-access_log common
</VirtualHost>
ServerAdmin admin@aaa.com
DocumentRoot "D:/root/webroot/aaa"
ServerName www.aaa.com
ServerAlias *.aaa.com
DirectoryIndex index.jsp index.php index.htm index.html
ErrorLog logs/aaa.example.com-error_log
CustomLog logs/aaa.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin@bbb.com
DocumentRoot "D:/root/webroot/bbb"
ServerName www.bbb.com
ServerAlias *.bbb.com
DirectoryIndex index.jsp index.php index.htm index.html
ErrorLog logs/bbb.example.com-error_log
CustomLog logs/bbb.example.com-access_log common
</VirtualHost>
ServerAdmin admin@bbb.com
DocumentRoot "D:/root/webroot/bbb"
ServerName www.bbb.com
ServerAlias *.bbb.com
DirectoryIndex index.jsp index.php index.htm index.html
ErrorLog logs/bbb.example.com-error_log
CustomLog logs/bbb.example.com-access_log common
</VirtualHost>
2>.修改D:\root\Tomcat 5.5\server.xml 文件:
<Host name="www.aaa.com" appBase="D:\root\webroot\aaa"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<alias>aaa.com</alias>
<alias>aaa</alias>
<Context path="" docBase="D:\root\webroot\aaa" debug="0" reloadable="true"/>
<alias>aaa</alias>
<Context path="" docBase="D:\root\webroot\aaa" debug="0" reloadable="true"/>
</Host>
<Host name="www.bbb.com" appBase="D:\root\webroot\bbb"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<alias>bbb.com</alias>
<alias>bbb</alias>
<Context path="" docBase="D:\root\webroot\bbb" debug="0" reloadable="true"/>
<alias>bbb</alias>
<Context path="" docBase="D:\root\webroot\bbb" debug="0" reloadable="true"/>
</Host>
同时在D:\root\webroot\aaa和D:\root\webroot\bbb放入相应的测试文件,重启Apache与Tomcat.
注:现在jsp文件不用放入ROOT目录中