KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Getting error when I try to run export #2474

Open Richb201 opened this topic on on Dec 1, 2021 - 37 comments

Richb201 commented on Dec 1, 2021

An uncaught Exception was encountered Type: Exception

Message: Could not execute phantomjs

Filename: /app/vendor/koolreport/export/Handler.php

Line Number: 67

Sebastian Morales commented on Dec 2, 2021

Pls make sure the file koolreport/export/bin/phantomjs (Linux) or koolreport/export/bin/phantomjs.exe (Windows) exists and your php user has executable right to it. Tks,

Richb201 commented on Dec 2, 2021

Its permission is 775. I think that has it covered?

Richb201 commented on Dec 2, 2021

I also tried sudo chmod +x app/vendor/koolreport/export/bin/phantomjs I am on ubuntu. Any other ideas?

Sebastian Morales commented on Dec 3, 2021

It could also be a temporary directory's write permission issue. Pls try to use a local temp like this:

$report->run()
->export("MyReportPDF")
->settings([
    'useLocalTempFolder' => true,    
])
->pdf(...)
...

Make sure your php user has write permission to the report's current directory (so that a temp dir and temp files could be created).

If this still doesn't solve the issue, pls open the file koolreport/export/Handler.php and replace this line:

        $result = shell_exec($command);

with these ones:

        echo "command = $command<br>"; exit;
        // $result = shell_exec($command);

Then run export and copy/paste the echoed command to your terminal to see if it can run or return any error. Let us know the result. Tks,

Richb201 commented on Dec 3, 2021

Hi. I am actually using this:

    $this->exec_summary();  //build the array
    $report = new MyExecutive_summary;
    $this->output->set_template('blank');
    $szFilename=sprintf("Executive_summary-%s-%s.pdf",$this->session->userdata('campaign'),$this->session->userdata('last_TY'));
    $report->export()->pdf(array(
        "format"=>"A4",
        "orientation"=>"portrait"
    ))->toBrowser($szFilename, FALSE); // Input the filename   make this true to pop open a window

I tried changing from FALSE to TRUE. My debugger is down so I can't check the $szFilename. Could that be the issue?

Sebastian Morales commented on Dec 6, 2021

Could it be that you forgot to run $report->run() before export it? Pls try this command and let us know the result:

$report
->run(); //add this method call
->export()
->pdf(array(
        "format"=>"A4",
        "orientation"=>"portrait"
    ))
->toBrowser($szFilename, FALSE);
Richb201 commented on Dec 6, 2021

Here is the code. Are you saying to $report->run() without the ->render()?

    $report = new MyNexusReport;
    $report->run()->render();

    $this->output->set_template('blank');
    $szFilename=sprintf("Specificity_report-%s-%s.pdf",$this->session->userdata('campaign'),$this->session->userdata('last_TY'));
    $report->export()->pdf(array(
        "format"=>"A4",
        "orientation"=>"portrait"
    ))->toBrowser($szFilename, FALSE); // Input the filename   make this true to pop open a window
Richb201 commented on Dec 7, 2021

Here is a hint: it runs fine on my laptop but comes up with that error on my EC2 server. Does that tell you anything?

Sebastian Morales commented on Dec 7, 2021

Pls try the steps in my previous post and let me know the result:

https://www.koolreport.com/forum/topics/2474#p13507

Richb201 commented on Dec 7, 2021

>>Make sure your php user has write permission to the report's current directory (so that a temp dir and temp files could be created).

What directory is the current report directory? I stopped the code in Handler.php with my debugger and when I look at FILE on line 113, I see "xdebug://debug-eval(1) : eval()'d code". I thought I would see a directory. What can I do?

Richb201 commented on Dec 7, 2021

I ran the echo command you mentioned above and then tried to run it in the terminal (on the server). this is what I got: ubuntu@ip-172-31-66-201:~$ command=/app/vendor/koolreport/export/bin/phantomjs --ignore-ssl-errors=true /app/vendor/koolreport/export/pdf/pdf.js /tmp/61af843c699522.tmp /tmp/61af843c6adab3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvc3RhZ2luZy5kYXNoYm9hcmQucmVzZWFyY2hzdHVkeW9ubGluZS5jb21cL2luZGV4LnBocFwvQ29uZmlndXJlXC9leGVjdXRpdmVfc3VtbWFyeSIsInJlc291cmNlV2FpdGluZyI6MTAwMH0= --ignore-ssl-errors=true: command not found

Sebastian Morales commented on Dec 8, 2021

1 . The local temp directory locates where your report setup and view files are, not inside "vendor/koolreport/export".

2 . Pls check phantomjs' screen capture examples with your installation at /app/vendor/koolreport/export/bin/phantomjs:

https://phantomjs.org/screen-capture.html

Richb201 commented on Dec 8, 2021

That could be the issue. When I look at printenv on the server I see:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Notice that the path with phantomjs is not on this. Should I modify the /etc/sysconfig/httpd to also have

/home/ubuntu/rst/RST/app/vendor/koolreport/export/bin

???

Richb201 commented on Dec 8, 2021

I grabbed the command trying to run phantomjs and removed the first "/" and at least it is found.

ubuntu@ip-172-31-66-201:~/rst/RST$ /app/vendor/koolreport/export/bin/phantomjs --ignore-ssl-errors=true /app/vendor/koolreport/export/pdf/pdf.js /tmp/61b0f98de8bb62.tmp /tmp/61b0f98de8e5f3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvc3RhZ2luZy5kYXNoYm9hcmQucmVzZWFyY2hzdHVkeW9ubGluZS5jb21cL2luZGV4LnBocFwvQ29uZmlndXJlXC9leGVjdXRpdmVfc3VtbWFyeSIsInJlc291cmNlV2FpdGluZyI6MTAwMH0=
-bash: /app/vendor/koolreport/export/bin/phantomjs: No such file or directory
ubuntu@ip-172-31-66-201:~/rst/RST$ ls /app/vendor/koolreport/export/bin/phantomjs
ls: cannot access '/app/vendor/koolreport/export/bin/phantomjs': No such file or directory
ubuntu@ip-172-31-66-201:~/rst/RST$ ls app/vendor/koolreport/export/bin/phantomjsapp/vendor/koolreport/export/bin/phantomjs
ubuntu@ip-172-31-66-201:~/rst/RST$ app/vendor/koolreport/export/bin/phantomjs --ignore-ssl-errors=true /app/vendor/koolreport/export/pdf/pdf.js /tmp/61b0f98de8bb62.tmp /tmp/61b0f98de8e5f3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvc3RhZ2luZy5kYXNoYm9hcmQucmVzZWFyY2hzdHVkeW9ubGluZS5jb21cL2luZGV4LnBocFwvQ29uZmlndXJlXC9leGVjdXRpdmVfc3VtbWFyeSIsInJlc291cmNlV2FpdGluZyI6MTAwMH0=
Error: Cannot find module '../common/base64_decode'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require

Richb201 commented on Dec 9, 2021

I ran the example cited in https://phantomjs.org/screen-capture.html and it ran fine.

Richb201 commented on Dec 12, 2021

Since I can't get Export to run I am going to build the report to the screen and then a user can print the screen. I am using this

   public function nexus_report()
    {
        $report2 = new MyNexusReport;
        $report2->run()->render();

But I need this report to be rendered in a new tab. How can I do this?

Sebastian Morales commented on Dec 13, 2021

I think we can still try to fix the phantomjs path issue. Pls try to set phantomjs path directly in setting like this:

    $report->run()->export("MyReportPDF")
    ->settings([
        'useLocalTempFolder' => true,
        'autoDeleteLocalTempFile' => true,
        'phantomjs' => 'path/to/your/phantomjs',
    ])
    ->pdf(...)
    ...

Still keep this output command in Handler.php:

        echo "command = $command<br>"; exit;
        // $result = shell_exec($command);

Then copy/paste the output phantomjs command to your terminal to see how it runs. Let us know the result. Tks,

Richb201 commented on Dec 13, 2021
richb201@richb201-XPS-13-9370:~$ app/vendor/koolreport/export/bin/phantomjs --ignore-ssl-errors=true /app/vendor/koolreport/export/pdf/pdf.js /app/vendor/koolreport/export/tmp/61b7571ff1d356.tmp /app/vendor/koolreport/export/tmp/61b7572848af17.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvc3RhZ2luZy5kYXNoYm9hcmQucmVzZWFyY2hzdHVkeW9ubGluZS5jb21cL2luZGV4LnBocFwvQ29uZmlndXJlXC9uZXh1c19yZXBvcnQiLCJyZXNvdXJjZVdhaXRpbmciOjEwMDB9
bash: app/vendor/koolreport/export/bin/phantomjs: No such file or directory


Sebastian Morales commented on Dec 13, 2021

Pls set 'phantomjs' => 'path/to/your/phantomjs' using a correct path, such as "~/rst/RST/app/vendor/koolreport/export/bin/phantomjs".

Richb201 commented on Dec 13, 2021
ubuntu@ip-172-31-66-201:~/rst/RST$ ~/rst/RST/app/vendor/koolreport/export/bin/phantomjs --ignore-ssl-errors=true /app/vendor/koolreport/export/pdf/pdf.js /app/vendor/koolreport/export/tmp/61b75e68b68036.tmp /app/vendor/koolreport/export/tmp/61b75e68b6ab37.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvc3RhZ2luZy5kYXNoYm9hcmQucmVzZWFyY2hzdHVkeW9ubGluZS5jb21cL2luZGV4LnBocFwvQ29uZmlndXJlXC9uZXh1c19yZXBvcnQiLCJyZXNvdXJjZVdhaXRpbmciOjEwMDB9
Error: Cannot find module '../common/base64_decode'

  phantomjs://platform/bootstrap.js:299 in require
  phantomjs://platform/bootstrap.js:263 in require


Sebastian Morales commented on Dec 14, 2021

It seems to be a problem with the real path to your phantomjs installation. Pls try to add ~/rst/RST/app/vendor/koolreport/export/bin to your system path and use this path setting:

    ->settings([
        ...
        'phantomjs' => 'phantomjs',
    ])
    ->pdf(...)
Richb201 commented on Dec 14, 2021

Here is my path already from printenv:

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/rst/RST/app/vendor/koolreport/export/bin
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/printenv

Sebastian Morales commented on Dec 15, 2021

Pls set your system then try to run "phantomjs -v" to make sure it could be found. Then use settings "phantomjs" => "phantomjs" when exporting to see and run manually the phantomjs command it outputs. Tks,

Richb201 commented on Dec 15, 2021

OK. I did that. phantomjs -v returns 2.1.1. I then ran my code and it printed this which I then ran from the CLI:

ubuntu@ip-172-31-66-201:~$ phantomjs --ignore-ssl-errors=true /app/vendor/koolreport/export/pdf/pdf.js /tmp/61b9eeb9320de2.tmp /tmp/61b9eeb9322f93.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJleHBlY3RlZExvY2F0aW9uIjoiaHR0cDpcL1wvc3RhZ2luZy5kYXNoYm9hcmQucmVzZWFyY2hzdHVkeW9ubGluZS5jb21cL2luZGV4LnBocFwvQ29uZmlndXJlXC9leGVjdXRpdmVfc3VtbWFyeSIsInJlc291cmNlV2FpdGluZyI6MTAwMH0=
Can't open '/app/vendor/koolreport/export/pdf/pdf.js'

I

Sebastian Morales commented on Dec 16, 2021

This seems to be a problem with accessing right to koolreport directory. Can you manually browse to /app/vendor/koolreport/export/pdf/pdf.js and open it?

Richb201 commented on Dec 16, 2021

Sebastian, I will check. I do not think that koolreport was installed on the EC2 server. Rather, it was copied to the EC2 server from my laptop. Could a reinstall directly to the EC2 help?

I tried to acces it via the cli but it is not found. Then I looked for it with filezilla. I can see that it is there. File permissions is 644. On my listing from printenv below you can see it is not there. Are there certain paths that need to be set up to allow koolreport to work properly?

ubuntu@ip-172-31-66-201:~$ cat /app/vendor/koolreport/export/pdf/pdf.js
cat: /app/vendor/koolreport/export/pdf/pdf.js: No such file or directory

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/ubuntu/rst/RST/app/vendor/koolreport/export/bin

Sebastian Morales commented on Dec 17, 2021

I think that when you copy KoolReport directory from your machine to EC2 somehow your webserver could not either figure out the exact file path or at least access the path it has for KoolReport directory (in this case: /app/vendor/koolreport).

Maybe a direct KoolReport install with composer via terminal on EC2 could help. Pls try it.

Regarding system path, in most cases webservers know the path to a directory or a file in their web directory so there's no need to set any system path. You only need to set one for phantomjs if you install it outside of koolreport/export/bin.

Richb201 commented on Dec 17, 2021

Well, as a "joke" I ran printenv on my Ubuntu laptop (where it runs fine). Here is what it printed:

PATH=/usr/lib/jvm/java-8-oracle/bin:/home/richb201/.npm-global/bin:/home/richb201/bin:/opt/gradle/gradle-5.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/richb201/Vault:/usr/local/java/jdk1.7.0_80/bin:/usr/local/java/jdk1.7.0_80/bin:/Home/richb201/Android/Sdk/emulator:/Home/richb201/Android/Sdk/tools:/Home/richb201/Android/Sdk/platform-tools:/home/richb201/Android/Sdk/emulator:/home/richb201/Android/Sdk/tools:/home/richb201/Android/Sdk/tools/bin:/home/richb201/Android/Sdk/platform-tools:/home/richb201/Documents/Android/sdk:/home/richb201/Documents/Android/Sdk/tools:/home/richb201/Android/tools/bin:/usr/bin/javac:/home/richb201/Documents/Android/sdk/platform-tools:/home/richb201/.npm-global/bin:/usr/lib/jvm/java-8-oracle/bin:/opt/gradle/gradle-5.0/bin

There is lots of stuff but I don't see koolreport at all. So that probably is not it. Can I change the rights to the entire koolreport directory (on the EC2 server) at the same time?

Sebastian Morales commented on Dec 20, 2021

The problem is not system/environment path. It's that your webserver can not get the path to KoolReport directory. To it the path is /app/vendor/koolreport which in reality doesn't exist. I still recommend installing KoolReport directly on your EC2 instance and see if it solves this web directory path problem.

Richb201 commented on Dec 20, 2021

OK. I ran composer on the EC2 server. Am I OK?

ubuntu@ip-172-31-66-201:~/rst/RST$ composer require koolreport/core
Warning from https://packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Using version ^5.5 for koolreport/core
./composer.json has been updated
Loading composer repositories with package information
Warning from https://packagist.org: Support for Composer 1 is deprecated and some packages will not be available. You should upgrade to Composer 2. See https://blog.packagist.com/deprecating-composer-1-support/
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
  - Installing koolreport/core (5.5.0): Downloading (100%)         
Writing lock file
Generating autoload files

BTW, it is still not working. Do I need to upgrade to composer 2 first? It seems to have installed koolreport/core.

Sebastian Morales commented on Dec 21, 2021

Your composer only install koolreport/core. Pls set the composer.json and auth.json so that you install koolreport/export or koolreport/pro as well:

https://www.koolreport.com/docs/export/overview/#installation-by-composer

Richb201 commented on Dec 24, 2021

It seems that the problem is line 50 of Handler.php. This is what the line shows:

$this->phantomjs = realpath(dirname(__FILE__))."/bin/phantomjs";

What $this->phantomjs returns is /app/vendor/koolreport/export/bin/phantomjs

But realpath should return /home/ubuntu/rst/RST/app/vendor/koolreport/export/bin/phantomjs which is the full path.

SYNOPSIS top

   realpath [OPTION]... FILE...

DESCRIPTION top

   Print the resolved absolute file name; all but the last component
   must exist

   -e, --canonicalize-existing
          all components of the path must exist

   -m, --canonicalize-missing
          no path components need exist or be a directory

   -L, --logical
          resolve '..' components before symlinks

   -P, --physical
          resolve symlinks as encountered (default)

   -q, --quiet
          suppress most error messages

   --relative-to=DIR
          print the resolved path relative to DIR

   --relative-base=DIR
          print absolute paths unless paths below DIR

   -s, --strip, --no-symlinks
          don't expand symlinks

   -z, --zero
          end each output line with NUL, not newline

   --help display this help and exit

   --version
          output version information and exit
Sebastian Morales commented on Dec 24, 2021

Yes, you judged the problem correctly. We are still trying to figure out why realpath didn't return real paths to phantomjs and export's js files for your case. Even if you use symlinks realpath can still find the correct absolute paths because resolving symlinks is on by default.

Richb201 commented on Apr 17, 2022

It has been five months since I ran into this bug. On Dec 24 2021, your comment implies that you are still working on this. Has any progress resolving this issue occurred?

Rich

Sebastian Morales commented on Apr 18, 2022

We can not replicate your problem (real path to phantomjs and export's resource files) on both your test and server environments so it's very hard to solve your case. If you still want to solve this pls email us (support@koolreport.com / support@koolphp.net) access to your test/server environment where this issue happens. Tks,

Richb201 commented on Apr 18, 2022

Hi Sebastion. The code is up on AWS ec2 server. How would I give you access? I have a remote debug working so if you tell me exactly what to look for I can check it.

Just to confirm, exactly what files am I missing the paths for?

Sebastian Morales commented on Apr 18, 2022

SSH terminal connection to your instance would be good enough.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None