Cannot get Aspose.Cells for PHP via Java to work

I am unable to get Aspose.Cells for PHP via Java to work in my ubuntu localhost. The documentation is not clear too Setup and Installation Guidelines|Documentation. Can anyone help me please.

I followed the steps given in the doc above. Tried on php 7.3, 7.4, 8.1 (with latest fix for php8)

Error:

2023/10/29 16:47:21 [error] 26547#26547: *2 FastCGI sent in stderr: "PHP message: PHP Fatal error:  <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Invalid URI</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><hr class="line" /><h3>Apache Tomcat/10.1.15</h3></body></html> in /var/www/html/pdftool/aspose.cells/Java.php8.inc on line 900" while reading response header from upstream, client: 127.0.0.1, server: _, request: "GET /pdftool/aspose.cells/example.php HTTP/2.0", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "localhost.com"

@rbncha,

The error may not be related to Aspose.Cells for Php, rather it is related to configurations or with your environment. We will evaluate your issue and get back to soon.
Please also make sure you have followed all the instructions and guidelines mentioned in the document.

1 Like

Thanks @amjad.sahi
Yes I followed the docs. I get confused with this doc however

The installation steps says to test
http://localhost:8080/JavaBridge/test.php

My Tomcat is running under 8080 and nginx under 80 ports
This means I should be doing http://localhost/JavaBridge/test.php ? Done and running good.

I think the issue is with Tomcat trying and not being able to call php from javaBridge.jar

This is what I am doing…

  • my php aspose.cells is at http://localhost.com/aspose.cells/example.php
  • I kept and modified /var/www/html/aspose.cells/Java.inc for define ("JAVA_HOSTS", "127.0.0.1:8080"); as my tomcat runs at 8080 port and nginx on 80
  • copied javaBridge.jar to both /var/www/html/aspose.cells/javaBridge.jar and /opt/tomcat/webapps/JavaBridge.jar
  • restarted tomcat and nginx from sudo systemctl restart tomcat nginx

Let me know what do you think

@rbncha
Thank you for your feedback and detailed information. You can access the link normally http://localhost/JavaBridge/test.php, it can be explained that the Php environment is normal. To access it normally http://localhost.com/JavaBridge/example.php, you still need to take more steps. Please confirm if the following three steps have been completed.

  1. Copy aspose-cells-xx.x.jar, bcpkix-jdk15on-xxx.jar and bcprov-jdk15on-xxx.jar to lib folder such as \java\apache-tomcat-9.0.24\lib folder.
  2. Copy aspose.cells.php and example.php to \java\apache-tomcat-9.0.24\webapps\JavaBridge folder.
  3. Modify the example.php file to ensure that the reference path used in the file is correct.
    for example:
    require_once(“java/Java.inc”);
    require_once(“aspose.cells.php”);

If you still encounter issues, please provide us with the log of tomcat. We will check it soon.

Hello @John.He

Thanks for the reply.

  • My tomcat is installed in /op/tomcat/. JavaBridge is located at /opt/tomcat/webapps/JavaBridge
    image.png (33.5 KB)

  • All three files (aspose-cells-23.10.jar, bcpkix-jdk15on-1.68.jar and bcprov-jdk15on-1.68.jar) are located inside /opt/tomcat/lib/
    image.png (43.5 KB)

  • modified /opt/tomcat/webapps/JavaBridge/example.php to require Java.inc and did php example in shell. Same error.

  • modified /var/www/html/aspose.cells/example.php to require Java.inc as require_once('http://localhost.com:8080/JavaBridge/Java.inc'); require_once('http://localhost.com:8080/JavaBridge/aspose.cells.php'); and browsed from browser as http://localhost.com/aspose.cells/example.php. Same error.

  • Tomcat log localhost_access_log.2023-10-30.txt

127.0.0.1 - - [30/Oct/2023:12:51:12 +0545] "PUT /JavaBridge/JavaBridge.phpjavabridge HTTP/1.1" 405 686
127.0.0.1 - - [30/Oct/2023:13:02:00 +0545] "GET /JavaBridge/Java.php8.inc HTTP/1.1" 200 88522
127.0.0.1 - - [30/Oct/2023:13:02:44 +0545] "GET /JavaBridge/aspose.cells.php HTTP/1.1" 200 131824
127.0.0.1 - - [30/Oct/2023:13:03:43 +0545] "GET /JavaBridge/Java.php8.inc HTTP/1.1" 200 88522
127.0.0.1 - - [30/Oct/2023:13:03:43 +0545] "GET /JavaBridge/aspose.cells.php HTTP/1.1" 200 131824
127.0.0.1 - - [30/Oct/2023:13:03:43 +0545] "PUT //servlet.phpjavabridge HTTP/1.1" 405 686
127.0.0.1 - - [30/Oct/2023:13:03:50 +0545] "GET /JavaBridge/Java.php8.inc HTTP/1.1" 200 88522
127.0.0.1 - - [30/Oct/2023:13:03:50 +0545] "GET /JavaBridge/aspose.cells.php HTTP/1.1" 200 131824
127.0.0.1 - - [30/Oct/2023:13:03:50 +0545] "PUT //servlet.phpjavabridge HTTP/1.1" 405 686
127.0.0.1 - - [30/Oct/2023:13:05:51 +0545] "PUT /JavaBridge/JavaBridge.phpjavabridge HTTP/1.1" 405 686
127.0.0.1 - - [30/Oct/2023:13:06:34 +0545] "PUT /JavaBridge/JavaBridge.phpjavabridge HTTP/1.1" 405 686
127.0.0.1 - - [30/Oct/2023:13:06:46 +0545] "PUT /JavaBridge/JavaBridge.phpjavabridge HTTP/1.1" 405 686

@rbncha
Can you access the following link normally?
http://localhost.com:8080/JavaBridge/example.php
Additionally, your log does not contain any error information.
Please share your environmental information, including but not limited to Java, Aspose.Cells for PHP via Java and PHP version information. This is very helpful for us to reproduce the issue.

@John.He

Yes I can access the link. Output is like this
image.png (25.7 KB)

But I think I should be doing http://localhost.com/aspose.cells/example.php instead. I am not sure.

In my tomcat log you can see this 405 header. It is access log localhost_access_log.2023-10-30.txt not error log. Nothing in error log.

127.0.0.1 - - [30/Oct/2023:13:03:43 +0545] “PUT //servlet.phpjavabridge HTTP/1.1” 405 686

My machine setup is:

  • Ubuntu 22.04
  • Nginx to run php8.1-fpm as default
  • Nginx http and/or https on https://localhost or https://localhost.com at /var/www/html/ doc root
  • Apache Tomcat/10.1.15 at /opt/tomcat/ (doc root at /opt/tomcat/webapps/)
  • java -version shows below
    image.png (25.6 KB)
  • Aspose.Cells for PHP via Java version aspose-cells-23.10.
  • tomcat at http://localhost:8080
    image.png (153.7 KB)

@rbncha
Thank you for providing those details. We will investigate it further and get back to you later.

@rbncha
By deploying two projects for testing, we can discover some errors. When a project references another project’s PHP file, an error will be reported. Please also copy the aspose.cells.php file to the new project. After copying the aspose.cells.php file and changing the references in example.php, we can access it normally. Please refer to the attachment (26.1 KB).

Modify the example.php file under the new project to ensure that the reference path used in the file is correct.
for example:

require_once("http://localhost:8080/JavaBridge/Java.inc");
require_once("aspose.cells.php");