WIN2000+PHP+MYSQL+TOMCAT+JSP完全整合安裝手冊
2024-09-05 00:19:36
供稿:網友
一、前期準備情況
1。一個安裝好的win2000服務器,注意:如果預裝了iis,請先將iis服務停掉或禁用。
2。下栽軟件
apache:版本:1.3.22 ——apache_1.3.22-win32-x86.msi
jdk:版本: 1.3 ——j2sdk1_3_0-win.exe
php: 版本: 4.0.4 ——php4.0.4pl1-win32.zip
mysql: 版本:3.23.32 ——mysql-3.23.32-win.zip
tomcat:版本: 4.0.4 ——jakarta-tomcat-4.0.4.exe
mod_jk:這是jakarta組織開發的使apache支持tomcat的插件,比apachejserv更強大,因為apachejserv
只能用在apache上,而不能用在別的webserver 上,mod_jk可以和很多服務器搭配起來用。
下載地址:http://jakarta.apache.org/builds/jakarta-tomcat/release/v3.3/bin/win32/i386/
(如果在提供的網址內找不到相應的軟件,請在各大網上軟件庫找,一般都有!或發郵件至[email protected])
3。準備好足夠的干糧和水,作好反復安裝和重新啟動的心理準備,但只要細心按照要求去做,一次成功不是什么
難事!
4。做一口深呼吸,別在想mm了!開始安裝!
二、安裝開始
1。apache安裝
第一步:運行apache_1.3.22-win32-x86.msi,一路點確定和接受就行,基本比較傻瓜,為了方便期間和符合我
的習慣我安裝的默認路徑是 c:/ ,這樣就安裝在c盤下的apache的路徑下,同時默認域為root.dev。
第二步:(我在這里作了一個虛擬主機,此步可以不做,根據你自己的需求)
編輯c:/apache/conf/httpd.conf
找到 #namevirtualhost *
修改為 namevirtualhost 192.168.0.16 #注意這個ip為你自己主機設的ip
找到 servername root.dev
修改為 #servername root.dev
添加
<virtualhost 192.168.0.16>
serveradmin [email protected]
servername root.dev
documentroot c:/apache/htdocs
errorlog c:/apache/logs/error_log
transferlog c:/apache/logs/access_log
scriptalias /cgi-bin c:/apache/cgi-bin
</virtualhost>
第三步:將文件名 c:/apache/htdocs/index.html.en 改為c:/apache/htdocs/index.html
第四步:重新啟動,訪問 http://root.dev 瀏覽正常,顯示apache歡迎頁
------------小小的成功!可以喝口水了!----------------------------
2。mysql安裝
第一步: 解壓 mysql-3.23.32-win.zip 到目錄 d:/mysql
第二步: 進入d:/mysql 運行setup.exe 一路回車,默認安裝到 c:/mysql
------------這一步應該沒有什么問題!-------------------------------
3。php安裝
第一步: 解壓 php4.0.4pl1-win32.zip 到目錄 d:/php
第二步: 將d:/php下拷貝到c盤根目錄下
第三步: 進入c:/php ,開始配置php
將文件名 php.ini-dist 改為 php.ini
同時拷貝 php.ini 和 php4ts.dll 到win2000的系統安裝目錄下
的 system32和system目錄下 (很重要,別忘了)
再次修改apache的配置文件httpd.conf (忘了吧!在c:/apache/conf/httpd.conf)
添加:
loadmodule php4_module c:/php/sapi/php4apache.dll
addtype application/x-httpd-php .php4
scriptalias /php4/ "c:/php/"
action application/x-httpd-php4 "/php4/php.exe"
addtype application/x-httpd-php4 .php
第四步: 重新啟動系統
第五步: 測試
編寫測試文件 info.php (拷貝到目錄 c:/apache/htdocs/ 下)
文件內容:(就一行)
<? phpinfo(); ?>
訪問: http://localhost/info.php 或 http://root.dev/info.php
如果看到php的歡迎測試頁面,說明安裝成功!
到目前為止,你的系統已經可以運行php程序了!
你已經配置好了 win2000+apache+php+mysql
----------------成功在望!吃些干糧,想5分鐘mm,上趟廁所,或者騷擾一下隔壁的大哥---------
---如果你能確定2件事就可以往下進行了:
1.你的智商確實比中國足協的那堆廢物高
2.真的很想進入jsp的世界遨游
4。jdk的安裝
第一步:直接運行 j2sdk1_3_0-win.exe,一路回車安裝,我這里默認的安裝路徑為d:/jdk1.3
第二步:配置環境變量
在我的電腦上點擊鼠標右鍵-屬性-點選高級-點選環境變量
彈出環境變量對話框,新建以下變量名和值:
-------------------------------------
變量名:path
變量值:d:/jdk1.3/bin
變量名:java_home
變量值:d:/jdk1.3
變量名:classpath
變量值:./;d:/jdk1.3/lib/dt.jar;d:/jdk1.3/lib/tools.jar;
第三步:重新啟動計算機使配置的環境變量生效
5。tomcat安裝
第一步:直接運行安裝jakarta-tomcat-4.0.4.exe,我這里默認的安裝路徑是c:/apache tomcat 4.0
這時如果單獨啟動tomcat(到tomca目錄下運行startup.bat啟動tomcat或在菜單欄運行start
tomcat),就已經可以運行jsp文件了,但是我們還沒有將apache和tomcat集成在一起,因為
雖然tomcat有內置的一個apache的http服務,但是他僅僅對jsp程序體現出比較好的執行效率
和性能,對于靜態頁面的處理速度遠不如apache,所以為了一個完美的web系統,我們要將
apache和tomcat集成在一起!
(下面就是集成他們的具體配置步驟,請注意仔細認真,我搞了1天才終于搞定?。?
第二步:先配置apache
打開c:/apache/conf/httpd.conf
添加以下語句:
#------------------------------------------
loadmodule jk_module libexec/mod_jk.dll
addmodule mod_jk.c
jkworkersfile "c:/apache tomcat 4.0/conf/worker.properties"
jklogfile logs/mod_jk.log
jkloglevel info
jklogstampformat "[%a %b %d %h:%m:%s %y] "
jkmount /*.jsp ajp13
jkmount /servlet/* ajp13
#-----------------------------------------------------
注意:以上語句的基本意思是:
第一、二句:指定apache和tomcat連接插件的位置和名稱
第三句:指出mod_jk工作所需要的工作文件的位置
第七、八句:是將所有和jsp和servlet的請求通過apj13的協議送給tomcat,讓tomcat來處理
第三步:將下載的mod_jk.dllcopy到安裝apache目錄下的libexec下就可以了
第四步:tomcat配置
首先是在c:/apache tomcat4.0/conf目錄下建一個worker.properties
文件內容如下:
#----------------------------------------------------------
# $header: /home/cvs/jakarta-tomcat/src/etc/attic/workers.properties,v 1.3.2.2 2000/10/16 01:59:22 larryi exp $
# $revision: 1.3.2.2 $
# $date: 2000/10/16 01:59:22 $
#
#
# workers.properties -
#
# this file provides jk derived plugins with with the needed information to
# connect to the different tomcat workers.
#
# as a general note, the characters $( and ) are used internally to define
# macros. do not use them in your own configuration!!!
#
# whenever you see a set of lines such as:
# x=value
# y=$(x)something
#
# the final value for y will be valuesomething
#
# normaly all you will need to modify is the first properties, i.e.
# workers.tomcat_home, workers.java_home and ps. most of the configuration
# is derived from these.
#
# when you are done updating workers.tomcat_home, workers.java_home and ps
# you should have 3 workers configured:
#
# - an ajp12 worker that connects to localhost:8007
# - an ajp13 worker that connects to localhost:8009
# - a jni inprocess worker.
# - a load balancer worker
#
# however by default the plugins will only use the ajp12 worker. to have
# the plugins use other workers you should modify the worker.list property.
#
#
#
# workers.tomcat_home should point to the location where you
# installed tomcat. this is where you have your conf, webapps and lib
# directories.
#
workers.tomcat_home=c:/apache tomcat 4.0
#
# workers.java_home should point to your java installation. normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=d:/jdk1.3
#
# you should configure your environment slash... ps= on nt and / on unix
# and maybe something different elsewhere.
#
ps=/
# ps=/
#
#------ advanced mode ------------------------------------------------
#---------------------------------------------------------------------
#
#
#------ default worket list ------------------------------------------
#---------------------------------------------------------------------
#
#
# the workers that your plugins should create and work with
#
worker.list=ajp12, ajp13
#
#------ default ajp12 worker definition ------------------------------
#---------------------------------------------------------------------
#
#
# defining a worker named ajp12 and of type ajp12
# note that the name and the type do not have to match.
#
worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
#
# specifies the load balance factor when used with
# a load balancing worker.
# note:
# ----> lbfactor must be > 0
# ----> low lbfactor means less work done by the worker.
worker.ajp12.lbfactor=1
#
#------ default ajp13 worker definition ------------------------------
#---------------------------------------------------------------------
#
#
# defining a worker named ajp13 and of type ajp13
# note that the name and the type do not have to match.
#
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
#
# specifies the load balance factor when used with
# a load balancing worker.
# note:
# ----> lbfactor must be > 0
# ----> low lbfactor means less work done by the worker.
worker.ajp13.lbfactor=1
#
# specify the size of the open connection cache.
#worker.ajp13.cachesize
#
#------ default load balancer worker definition ----------------------
#---------------------------------------------------------------------
#
#
# the loadbalancer (type lb) workers perform wighted round-robin
# load balancing with sticky sessions.
# note:
# ----> if a worker dies, the load balancer will check its state
# once in a while. until then all work is redirected to peer
# workers.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=ajp12, ajp13
#
#------ default jni worker definition---------------------------------
#---------------------------------------------------------------------
#
#
# defining a worker named inprocess and of type jni
# note that the name and the type do not have to match.
#
worker.inprocess.type=jni
#
#------ classpath definition -----------------------------------------
#---------------------------------------------------------------------
#
#
# additional class path components.
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)classes
#
# the xml parser provided with tomcat
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)jaxp.jar
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)parser.jar
#
# tomcat`s implementation
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)jasper.jar
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)servlet.jar
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)webserver.jar
#
# javac as available from java2se
#
worker.inprocess.class_path=$(workers.java_home)$(ps)lib$(ps)tools.jar
#
# setting the command line for tomcat
# note: the cmd_line string may not contain spaces.
#
worker.inprocess.cmd_line=-config
worker.inprocess.cmd_line=$(workers.tomcat_home)/conf/jni_server.xml
worker.inprocess.cmd_line=-home
worker.inprocess.cmd_line=$(workers.tomcat_home)
#
# the jvm that we are about to use
#
# this is for java2
#
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll
#
# and this is for jdk1.1.x
#
#worker.inprocess.jvm_lib=$(workers.java_home)$(ps)bin$(ps)javai.dll
#
#
# setting the place for the stdout and stderr of tomcat
#
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)inprocess.stderr
#
# setting the tomcat.home java property
#
worker.inprocess.sysprops=tomcat.home=$(workers.tomcat_home)
#
# java system properties
#
# worker.inprocess.sysprops=java.compiler=none
# worker.inprocess.sysprops=myprop=mypropvalue
#
# additional path components.
#
# worker.inprocess.ld_path=d:$(ps)sqllib$(ps)bin
#
#--------------------------------------配置文件完畢-------------------------------------
在這個文件中需要注意的是要修改只有兩個地方,一個是workers.tomcat_home,
這是指定tomcat工作的目錄,另外一個是workers.java_home,這是指定jdk的目
錄,大家可以做適當修改!我這里的配置沒有修改,都是符合我安裝系統的配置!
其次,配置tomcat核心文件,打開 c:/apache tomcat4.0/conf/server.xml
修改如下:
將<!-- define an ajp 1.3 connector on port 8009 -->
<!--
<connector classname="org.apache.ajp.tomcat4.ajp13connector"
port="8009" minprocessors="5" maxprocessors="75"
acceptcount="10" debug="0"/>
-->
的<!-- --> 去掉,這句話熟悉xml的人都知道它是注釋,因為默認的tomcat4
是沒有啟用apj13的8009的端口即mod_jk所使用,修改后如下:
<connector classname="org.apache.ajp.tomcat4.ajp13connector"
port="8009" minprocessors="5" maxprocessors="75"
acceptcount="10" debug="0"/>
然后保存,現在你的tomcat和apache的配置基本完成了。
第五步:所有配置基本完成,重新啟動計算機,開始整體測試!
測試:大家首先啟動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"%>
<html>
<body>
<%string str="hello world!";%>
<%str=str+"你好";%>
<%=str%>
</body>
</html>
將它保存到c:/apache tomcat 4.0/webapps/root下,然后在瀏覽器里輸入
http://localhost/hello.jsp如果看到了hello,那么您的確成功了。
------------------至此你已經大功告成,可以哼一個小曲了--------------------------
我的這個配置文檔是經過考驗,確實可以正常通過并運行的,希望能給你有所幫助,如果在進
行過程中有任何問題,請通知我!
我的qq:5359496
email:[email protected]
其次我再闡述兩個問題:
1。由于我在配置apache中使用了虛擬主機,所以訪問地址可以是:
http://localhost和http://root.dev,但是如果想http://root.dev訪問成功的話,請在
瀏覽器里做如下設置:
internet選項-連接-局域網設置
選擇 “使用代理服務器”,地址:192.168.0.16 (寫你主機的ip) 端口:80
2。對于apache主機下訪問的jsp文件,實際上物理上不存在與apache的主機上,而是存在在
tomcat的主機目錄里,例如:
http://localhost/hello.jsp 中hello.jsp文件實際不在 c:/apache/htdocs/下,而在
c:/apache tomcat 4.0/webapps/root 下。這點請注意,不要混淆概念!