瘋狂

          STANDING ON THE SHOULDERS OF GIANTS
          posts - 481, comments - 486, trackbacks - 0, articles - 1
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          環(huán)境:
          操作系統(tǒng):IBM aix5.3(當然linux環(huán)境和windows下肯定是沒問題的)

          1 運行php當然首選apache這里就不講apache方式了,可見于http://www.aygfsteel.com/freeman1984/archive/2011/06/10/352043.html,但是在aix下php和apache的結合始終沒有裝好,linux下我試過一點問題沒有。有成功的案例可以給個鏈接看看,謝謝!

          下面介紹兩種單獨使用tomcat運行php的:
          -------------------------------------------------------------------------------------------
          1 使用tomcat內置的cgi支持(需要安裝php環(huán)境,去官網下載就行了http://www.php.net/downloads.php,要注意的是,我在aix上5.X裝不上,用4.X的沒問題)
              相關文檔可見于tomcat的安裝目錄webapps下面的doc查看cgi-howto.html界面里面有介紹,當然tomcat5.X和6.X有不同的地方:
            5.X步驟:
          1 :Rename $CATALINA_BASE/server/lib/servlets-cgi.renametojar to $CATALINA_BASE/server/lib/servlets-cgi.jar.
            這個大家應該知道意思。
          2.Remove the XML comments from around the CGI servlet and servlet-mapping configuration in $CATALINA_BASE/conf/web.xml.(也就是添加cgi的servlet支持,打開注釋即可)
            具體如下:

              <servlet>
                  <servlet-name>cgi</servlet-name>
                  <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
                  <init-param>
                    <param-name>debug</param-name>
                    <param-value>0</param-value>
                  </init-param>
                  <init-param>
                    <param-name>cgiPathPrefix</param-name>
                    <param-value>WEB-INF/cgi</param-value>
                  </init-param>
                  <init-param>   
                   <param-name>passShellEnvironment</param-name>   
                    <param-value>true</param-value>   
                  </init-param> 
                   <load-on-startup>5</load-on-startup>
              </servlet>
          還有后面的mapping
          <!-- The mapping for the CGI Gateway servlet -->


              <servlet-mapping>
                  <servlet-name>cgi</servlet-name>
                  <url-pattern>/cgi-bin/*</url-pattern>
              </servlet-mapping>

          3 添加several servlet init parameters which can be used to configure the behaviour of the CGI servlet(添加幾個servlet的參數(shù))

          • cgiPathPrefix - The CGI search path will start at the web application root directory + File.separator + this prefix. The default cgiPathPrefix is WEB-INF/cgi(php文件放置的位置)
          • debug - Debugging detail level for messages logged by this servlet. Default 0.
          • executable - The of the executable to be used to run the script. Default is perl.(添加解析php的引擎)
          • parameterEncoding - Name of the parameter encoding to be used with the GCI servlet. Default isSystem.getProperty("file.encoding","UTF-8").
          • passShellEnvironment - Should the shell environment variables (if any) be passed to the CGI script? Default isfalse.

              我們需要添加executable 即可:windows下我的php引擎位置:D:\PHP\php-cgi.exe(aix下為/usr/local/php4/bin/php),因此在第二步里面添加下面參數(shù):
                <init-param> 
                 <param-name>executable</param-name>
                 <param-value>D:\PHP\php-cgi.exe</param-value> 
               </init-param> 
          tomcat6.X下面沒有第一步。
          4,測試,添加一個web應用,這里使用ROOT即可,編寫一個index.php放到webapps/ROOT/WEB-INF/cgi/下面內容:
          <?php  
             echo("helloworld"); 
          ?>
          啟動tomcat,訪問http://localhost:8080/cgi-bin/index.php即可。
          ---------------------------------------------------------------------------------

          另外一種方式是使用quercus:
              Quercus是Caucho公司采用純Java開發(fā)的一個PHP5引擎。基于開源授權協(xié)議GPL發(fā)布。Quercus自帶很多個PHP模塊和擴展如PDF,PDO,MySQL和JSON。可以利用這個引擎在一些JavaEE應用容器(Resin,GlassFish等)中運行PHP程序,也可以在PHP腳本中調用一些Java服務如JMS。Quercus會預先把PHP文件編譯成.java文件,然后再執(zhí)行。 http://quercus.caucho.com/
             當然可以使用resin作為服務器運行也可以,我們這里使用tomcat,需要jdk1.5以上(我試了1,4貌似不行,估計和我下載的quercus有關系),下面是步驟:
          1 我們把php項目當做一個web項目放在webapps下,并在里面建WEB-INF\lib目錄
          2 從http://quercus.caucho.com/。下載quercus-4.0.18.zip ,提取里面的web.xml放到
            WEB-INF下面,提取里面的cdi-16.jar,resin.jar放到WEB-INF\lib下面。
          3 啟動tomcat,
          4 像訪問j2ee web應用一樣訪問php應用即可。我們現(xiàn)在aix生產環(huán)境用的就是這種,比較穩(wěn)定。

          其他方式兄弟們可以擴充。

          主站蜘蛛池模板: 社旗县| 即墨市| 饶平县| 沂南县| 广州市| 崇明县| 白玉县| 莲花县| 梁平县| 姚安县| 商洛市| 河津市| 厦门市| 蕲春县| 阆中市| 封开县| 简阳市| 南城县| 辽源市| 库尔勒市| 同江市| 嘉峪关市| 隆子县| 崇信县| 佛冈县| 砀山县| 常德市| 普定县| 洛宁县| 赞皇县| 年辖:市辖区| 江津市| 武清区| 郁南县| 黎平县| 平罗县| 岢岚县| 梨树县| 七台河市| 泗阳县| 朝阳市|