安裝PHP5.2.5@Tomcat6

本文详细记录了将PHP5.2.5与Tomcat集成的过程,包括安装配置步骤、解决常见问题的方法及注意事项。对于希望在同一Web应用程序中启用PHP功能而非全局启用的用户来说尤为实用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

搞不定PHP5.3,只好找PHP5.2.5的來試,因為網路上找到的都是這個版本的...

PHP:php-5.2.5-Win32.zip (安裝位置後面用[color=red]%PHP%[/color]表示)
PECL:pecl-5.2.5-Win32.zip
TOMCAT:apache-tomcat-6.0.20.zip (安裝位置後面用[color=blue]%TOMCAT%[/color]表示)

PHP & PECL 5.25
[url]http://cid-4aaee94fa4376beb.skydrive.live.com/self.aspx/PHP/php%5E0pecl-5.2.5-Win32.rar[/url]

1.解壓縮Tomcat。
2.解壓縮PHP。
3.將[color=red]%PHP%[/color]添加至系統變量"PATH"。

4.將[color=red]%PHP%[/color]中的"php.ini-dist"改名為"php.ini"。
5.在"php.ini"中找到"Dynamic Extensions"部分,添加"extension=php_java.dll"。
[color=red]這裡好像少了一個將php.ini Copy 到 %WINDOWS%\ststem32,但是沒做也沒差?![/color]
[color=orange]下面一篇則是說得將修改後的php.ini放到%PHP%下面![/color]

另[url]http://tw.myblog.yahoo.com/davis-tseng/article?mid=199&sc=1[/url]
[quote]將 d:\php5 中的 php.ini-dist 改名為 php.ini,
在 d:\php5 中的 php.ini
找到 Dynamic Extensions 部分,
增加 extension=php_java.dll
增加 include_path = ".;d:\php5\pear"
將 [b];extension_dir = "./"[/b] 註記
增加 [b]extension_dir = "d:\php5\ext"[/b] [b]並 複製至 C:\WINDOWS[/b]
[/quote]

6.將"PECL 5.2.5 Win32 binaries"壓縮包中的" php5servlet.dll"解壓縮至[color=red]%PHP%[/color]。
7.將"PECL 5.2.5 Win32 binaries"壓縮包中的"php_java.dll"解壓縮至"[color=red]%PHP%[/color]\ext"。

8.在"[color=blue]%TOMCAT%[/color]\webapps"中建立應用程序目錄。(例如PHPTest)

9.將"PECL 5.2.5 Win32 binaries"壓縮包中的" phpsrvlt.jar"解壓縮至"[color=blue]%TOMCAT%[/color]\webapps\PHPTest\WEB-INF\lib"。
10. 解壓縮"phpsrvlt.jar"(jar xfv phpsrvlt.jar),將"net\php\reflect.properties"以及"net\php \servlet.properties"文件內容修改為"library=php5servlet"。(內容保持為一行,且任何位置不可有空格或其他符號)
11.重新建立"phpsrvlt.jar"壓縮包(jar cvf phpsrvlt.jar net/php/*.*)。

12.在"[color=blue]%TOMCAT%[/color]\webapps\PHPTest\WEB-INF"目錄建立"web.xml"描述
[b]web.xml[/b]
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<servlet-name>php</servlet-name>
<servlet-class>net.php.servlet</servlet-class>
</servlet>
<servlet>
<servlet-name>php-formatter</servlet-name>
<servlet-class>net.php.formatter</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>php-formatter</servlet-name>
<url-pattern>*.phps</url-pattern>
</servlet-mapping>
</web-app>


13.在"[color=blue]%TOMCAT%[/color]\webapps\PHPTest"目錄建立"phpinfo.php":
[b]phpinfo.php[/b]
<?php phpinfo(); ?>


14.啟動Tomcat。([color=blue]%TOMCAT%[/color]\bin\startup.bat)
15.使用閱覽器訪問"http://localhost:8080/PHPTest/phpinfo.php"。

參考:
[url]http://spoondrift.blogspot.com/2007/12/running-php-5x-on-windows-using-tomcat.html[/url]

Running php 5.x on windows using tomcat 4.x or 5.x
[url]http://blog.taragana.com/index.php/archive/running-php-5x-on-windows-using-tomcat-4x-or-5x/[/url]
[quote]What it solves:

1. Using php 5.x on Tomcat 4.x or 5.x
2. Enabling php only in one web application, instead of globally.


The simplest possible configuration is described. The descriptions are terse assuming your intelligence.

We will assume php will be installed in c:\ drive. Substitute with drive letter of your choice.

Instructions

1. Download latest php 5.x zip file.
I used [b]http://www.php.net/get/php-5.0.2-Win32.zip/from/a/mirror[/b] .
2. Download latest Collection of PECL modules. I used [b]http://www.php.net/get/pecl-5.0.2-Win32.zip/from/a/mirror[/b] .
3. Unzip php 5.x zip file anywhere, normally [b]c:\php[/b]
4. Copy php.ini-dist, in [b]c:\php[/b], as [b]php.ini[/b]
5. Uncomment the line (remove semi-colon at the beginning) in [b]php.ini[/b]:
[b];extension=php_java.dll[/b]
6. Extract [b]php5servlet.dll[/b] from [b]pecl[/b] zip file to [b]c:\php[/b] (Uncheck "Use Folder Names" in WinZip).
Ensure that the file is actually present in [b]c:\php[/b]
7. Install Tomcat and create a directory under webapps. Lets say it is named [b]fun[/b].
8. Create [b]WEB-INF[/b] directory under fun
9. Create [b]lib[/b] directory under WEB-INF
10. Create [b]web.xml[/b] under WEB-INF with the following contents:
同上

11. Extract [b]php5srvlt.jar[/b] and extract/unjar (jar xvf …) it under c:\
12. Modify both the files reflect.properties and servlet.properties to change the line [b]library=phpsrvlt[/b] to [b]library=php5servlet[/b] and save them. This indicates the file name of the dll file which is loaded by the Java application to serve the requests. In my version the name of the dll was [b]php5servlet.dll[/b]. Your mileage may vary. This has no connection with the name of the jar file which can be anything.
13. Re-create the jar file
14. Copy the jar file to WEB-INF\lib directory created earlier
15. Add c:\php to your System or User Path in Windows enironment (Hint: Right-click and select Properties from [b]My Computer[/b])
16. Create a file test.php under fun with the following code:

17. Start Tomcat (Go to [Tomcat installation directory]\bin and type Tomcat).
18. Open your browser and go to http://localhost:8080/fun/test.php
19. Ensure that there are no errors displayed. Instead you get an informative screen with php version information and whole lot of details

Let me know if this document is helpful to you.

Update: Made minor revision to highlight some key elements.

Solutions to common problems by users:
Whoever is getting this error 「java.lang.UnsatisfiedLinkError: no php5servlet in java.library.path」. Please check the two properties file, whether there are any blank spaces. I was stuck in this problem for 2 days. There should be only one line, and no blank spaces. Check it now!!!. This is where the problem is lying.
–Arundhati

The versions of php and pecl must be the same.
–Mirek Mocek

You might want to add a reboot step at the end of your instructions. It would eliminate a lot of the problems with the unsatisfied link errors.
– Chuck Rosendahl

Note:
If you find this tutorial useful, please consider donating and enjoy the pleasure of giving.
[/quote]

php5.2.6 in tomcat 6
[url]http://zkzk.pixnet.net/blog/post/22066545[/url]
[quote]System:
windows vista x86(*註1)
tomcat 6
php5.2.6
pecl5.2.6,actually 5.2.5(*註2)

Step:
1, download php-5.2.6-Win32.zip & pecl-5.2.6-Win32.zip & pecl-5.2.5-Win32.zip from http://www.php.net/.
=>之所以要下pecl-5.2.5-Win32.zip是因為5.2.6里面沒包php5Servlet.dll 跟 phpsrvlt.jar
=>如果php.net之後有修正pecl-5.2.5-Win32.zip,或是更新版本有包含上述的檔案,則不需要再下5.2.5版本。

2, unzip php-5.2.6-Win32.zip into a folder named such as "d:\php";

3, unzip pecl-5.2.6-Win32.zip into a new folder under "d:\php" named "pecl", i.e. "d:\php\pecl".
3.1,unzip php5Servlet.dll & phpsrvlt.jar from pecl-5.2.5-Win32.zip to the folder created in step 3.
=>比照step 1的敘述,如果有修正則step 3.1不需要再執行。

4, rename the file "php.ini.dist" in "d:\php" to "php.ini";

5, copy and rename "d:\php\pecl\php5servlet.dll" to "Tomcat6.0\bin\php5srvlt.dll", because in the packet phpsrvlt.jar the net/php/reflect.properties the configuration is library=php5srvlt, and the same with net/php/servlet.properties.
=>也可以逆向操作把phpservlet.jar裡面的兩個屬性檔案的內容改掉,重包jar。

6, copy "d:\php\pecl\phpsrvlt.jar" to "Tomcat6.0\lib";

7, modify "Tomcat\conf\web.xml"
add php servlet configuration:
------------------------------------------
<servlet>
<servlet-name>php</servlet-name>
<servlet-class>net.php.servlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
------------------------------------------
and add its servlet-map as following:

------------------------------------------
<servlet-mapping>
<servlet-name>php</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
------------------------------------------
=>我在這邊被vista 跟ultra edit聯手惡搞。vista的權限鎖的很緊。所以ultra edit要作存取跟產生備份檔案的動作全部都被擋下來。
=>但是雖然被擋了,ultra edit卻看不出被擋的跡象。一樣存檔,而且把檔案關掉之後,再從新開啟,是更改後的檔案內容。
=>然而從檔案管理員或是從資料夾進去,可以看到沒有產生bak檔案的同時,原始檔案的最後修改日期跟時間完全沒有變動。


8, set environment variables
PHP_HOME=d:\php
LD_LIBRARY_PATH=%PHP_HOME%;%PHP_HOME%/pecl
append %PHP_HOME%;;%PHP_HOME%/pecl; to the PATH variable.
=>我不知道LD_LIBRARY_PATH是否有必要要設定,因為別的參考版本似乎沒寫這個。我還是有設定。

9, restart Tomcat

10. prepare a test.php only with following single line
--------------------------------------
<?php phpinfo(); ?>

--------------------------------------
then put it into "Tomcat\webapps\Root"
try to access the test.php in your browser.

*註1:文中已經有提到vista是怎麼搞我的......我當時百思不解為甚麼好像都認不出*.php的檔案。
*註2:文中也有提到了,如果找不到就找5.2.5吧。只要點選pecl下載頁面,再把網址改一下他的version就可以了。看到許多人在問說要怎麼取得,所以特別寫一下(這種偷雞摸狗的事情).....

我就卡註這兩步,另外就是請注意step5的地方,讓屬性檔案跟實際的dll檔案名稱相同,網路上很多人卡在這裡。也不知道為甚麼開發的人會取不同名字。[/quote]


感覺上就是一個亂字,官方似乎也沒有一個統一或更便捷的方式來安裝,也許可以用ant來寫個build file,方便下次安裝。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值