KoolReport's Forum

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

Phantomjs sounds failed to generate pdf, and getting empty pdf #2626

Open FIMM opened this topic on on Apr 4, 2022 - 21 comments

FIMM commented on Apr 4, 2022

I have installed the phantomjs from here: https://github.com/Medium/phantomjs/releases/download/v2.1.1/$PHANTOM_JS.tar.bz2

In my dev server its working, however the staging server it doesnt. Staging server details:

root@d41d753ccdfa:/var/www/html# cat /etc/os-release
PRETTY_NAME="Ubuntu 21.10"
NAME="Ubuntu"
VERSION_ID="21.10"
VERSION="21.10 (Impish Indri)"
VERSION_CODENAME=impish
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=impish

--

root@d41d753ccdfa:/var/www/html# uname -r
5.4.0-65-generic

root@d41d753ccdfa:/var/www/html# cat /proc/version
Linux version 5.4.0-65-generic (buildd@lcy01-amd64-018) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021

Could you please help me to identify the problem and possible fix? Thanks in advance.

FIMM commented on Apr 4, 2022

Hi support, still have any chance have a look at it?

I have downloaded the binary from https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

FYI: I just checked that the ***.tmp file has all content to be write to pdf. However, pdf generating empty. Which place should I check? TQ

FIMM commented on Apr 5, 2022

Please suggest me, this bit urgent issue. I am using koolreport paid version.

TQ

Sebastian Morales commented on Apr 5, 2022

Hi, would you pls run the following standard examples of Phantomjs to see if your installation works:

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

FIMM commented on Apr 5, 2022

Hi, I just ran the command which seems worked there.

root@d41d753ccdfa:/var/www/html# phantomjs github.js
root@d41d753ccdfa:/var/www/html# ll -ah github.pdf
-rw-r--r-- 1 root root 1.8M Apr  5 04:55 github.pdf

Sebastian Morales commented on Apr 5, 2022

That's a good news. Now let's find out where it failed in the Export package. On your staging server pls open the file koolreport/export/Handler.php and replace the following line:

        $result = shell_exec($command);

with these ones:

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

Then try to export your report to see the output command. Copy and paste it to your server's terminal to run and see if there's any error message. Let us know the result. Tks,

FIMM commented on Apr 5, 2022

Hi, I did that and got this command and then I ran command. Kindly please see the output,

command = /usr/bin/phantomjs --ignore-ssl-errors=true /var/www/html/vendor/koolreport/export/pdf/pdf.js /var/www/html/public/tmp/624bfeea72a372.tmp /var/www/html/public/tmp/624bfeea72cff3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJ6b29tIjowLjUsIm1hcmdpbiI6eyJ0b3AiOiIwLjVpbiIsImJvdHRvbSI6IjAuNWluIiwibGVmdCI6IjAuNWluIiwicmlnaHQiOiIwLjVpbiJ9LCJoZWFkZXJDYWxsYmFjayI6ImZ1bmN0aW9uKGhlYWRlckNvbnRlbnQsIHBhZ2VOdW0sIG51bVBhZ2VzKXtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VOdW0gIT0gMSkgcmV0dXJuICcnOyBcL1wvZG9uJ3Qgc2hvdyBoZWFkZXIgZm9yIHRoZSAxc3QgcGFnZVxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaGVhZGVyQ29udGVudDtcbiAgICAgICAgICAgICAgICB9IiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHA6XC9cL2xvY2FsaG9zdFwvYXBpXC9tb2R1bGUwXC9hZG1pbnVzZXJsaXN0cGRmIiwicmVzb3VyY2VXYWl0aW5nIjoxMDAwfQ==

command output:

root@d41d753ccdfa:/var/www/html# /usr/bin/phantomjs --ignore-ssl-errors=true /var/www/html/vendor/koolreport/export/pdf/pdf.js /var/www/html/public/tmp/624bfeea72a372.tmp /var/www/html/public/tmp/624bfeea72cff3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJ6b29tIjowLjUsIm1hcmdpbiI6eyJ0b3AiOiIwLjVpbiIsImJvdHRvbSI6IjAuNWluIiwibGVmdCI6IjAuNWluIiwicmlnaHQiOiIwLjVpbiJ9LCJoZWFkZXJDYWxsYmFjayI6ImZ1bmN0aW9uKGhlYWRlckNvbnRlbnQsIHBhZ2VOdW0sIG51bVBhZ2VzKXtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VOdW0gIT0gMSkgcmV0dXJuICcnOyBcL1wvZG9uJ3Qgc2hvdyBoZWFkZXIgZm9yIHRoZSAxc3QgcGFnZVxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaGVhZGVyQ29udGVudDtcbiAgICAgICAgICAgICAgICB9IiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHA6XC9cL2xvY2FsaG9zdFwvYXBpXC9tb2R1bGUwXC9hZG1pbnVzZXJsaXN0cGRmIiwicmVzb3VyY2VXYWl0aW5nIjoxMDAwfQ==
1;/var/www/html/public/tmp/624bfeea72cff3.pdf

PDF file also created with content:

root@d41d753ccdfa:/var/www/html# ls -lah /var/www/html/public/tmp/624bfeea72cff3.pdf
-rw-r--r-- 1 root root __141K__ Apr  5 08:38 /var/www/html/public/tmp/624bfeea72cff3.pdf
Sebastian Morales commented on Apr 5, 2022

Pls copy and paste this command to your server's terminal and run it:

/usr/bin/phantomjs --ignore-ssl-errors=true /var/www/html/vendor/koolreport/export/pdf/pdf.js /var/www/html/public/tmp/624bfeea72a372.tmp /var/www/html/public/tmp/624bfeea72cff3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJ6b29tIjowLjUsIm1hcmdpbiI6eyJ0b3AiOiIwLjVpbiIsImJvdHRvbSI6IjAuNWluIiwibGVmdCI6IjAuNWluIiwicmlnaHQiOiIwLjVpbiJ9LCJoZWFkZXJDYWxsYmFjayI6ImZ1bmN0aW9uKGhlYWRlckNvbnRlbnQsIHBhZ2VOdW0sIG51bVBhZ2VzKXtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VOdW0gIT0gMSkgcmV0dXJuICcnOyBcL1wvZG9uJ3Qgc2hvdyBoZWFkZXIgZm9yIHRoZSAxc3QgcGFnZVxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaGVhZGVyQ29udGVudDtcbiAgICAgICAgICAgICAgICB9IiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHA6XC9cL2xvY2FsaG9zdFwvYXBpXC9tb2R1bGUwXC9hZG1pbnVzZXJsaXN0cGRmIiwicmVzb3VyY2VXYWl0aW5nIjoxMDAwfQ==

If there's no error pls check directory /var/www/html/public/tmp/ to see if there's any newly created pdf file called '624bfeea72cff3.pdf'

FIMM commented on Apr 5, 2022

Hi Sebastian, Thanks.

Yeah, I had run that, new pdf file has created. Kindly see my output below,

root@d41d753ccdfa:/var/www/html# /usr/bin/phantomjs --ignore-ssl-errors=true /var/www/html/vendor/koolreport/export/pdf/pdf.js /var/www/html/public/tmp/624c02178dc082.tmp /var/www/html/public/tmp/624c02178de3b3.pdf eyJmb3JtYXQiOiJBNCIsIm9yaWVudGF0aW9uIjoicG9ydHJhaXQiLCJ6b29tIjowLjUsIm1hcmdpbiI6eyJ0b3AiOiIwLjVpbiIsImJvdHRvbSI6IjAuNWluIiwibGVmdCI6IjAuNWluIiwicmlnaHQiOiIwLjVpbiJ9LCJoZWFkZXJDYWxsYmFjayI6ImZ1bmN0aW9uKGhlYWRlckNvbnRlbnQsIHBhZ2VOdW0sIG51bVBhZ2VzKXtcbiAgICAgICAgICAgICAgICAgICAgaWYgKHBhZ2VOdW0gIT0gMSkgcmV0dXJuICcnOyBcL1wvZG9uJ3Qgc2hvdyBoZWFkZXIgZm9yIHRoZSAxc3QgcGFnZVxuICAgICAgICAgICAgICAgICAgICByZXR1cm4gaGVhZGVyQ29udGVudDtcbiAgICAgICAgICAgICAgICB9IiwiZXhwZWN0ZWRMb2NhdGlvbiI6Imh0dHA6XC9cL2xvY2FsaG9zdFwvYXBpXC9tb2R1bGUwXC9hZG1pbnVzZXJsaXN0cGRmIiwicmVzb3VyY2VXYWl0aW5nIjoxMDAwfQ==
1;/var/www/html/public/tmp/624c02178de3b3.pdf
root@d41d753ccdfa:/var/www/html# 
root@d41d753ccdfa:/var/www/html# 
root@d41d753ccdfa:/var/www/html# ls -lah /var/www/html/public/tmp/624c02178de3b3.pdf
-rw-r--r-- 1 root root 141K Apr  5 08:47 /var/www/html/public/tmp/624c02178de3b3.pdf
Sebastian Morales commented on Apr 5, 2022

Can you pls view the content of /var/www/html/public/tmp/624c02178de3b3.pdf?

FIMM commented on Apr 5, 2022

Yeah, I have just downloaded the pdf. It has all the contents. for instance,

Sebastian Morales commented on Apr 5, 2022

Pls undo the change in Handler.php and run report export again. Then check directory /var/www/html/public/tmp/ to see if there's any newly created pdf file and view its content if there is.

FIMM commented on Apr 5, 2022

The pdf is created here while run it again after undoing the code: /var/www/html/public/tmp/624c153bb4ddc3.pdf I have downloaded it manually where the content is still empty!

FYI: I was trying to run shell_exec("command") which also able to create the pdf with content. If in case it helps you to guide me. thanks

Sebastian Morales commented on Apr 5, 2022

The web user on your server probably doesn't have enough right to either execute phantomjs or access to your system temporary directory. Pls find out your web user with this php script:

<?php
    echo shell_exec("whoami");

Then add executable right of phantomjs binary file and write permission of /var/www/html/public/tmp for that user.

FIMM commented on Apr 5, 2022

Hi, current permissions are:

root@d41d753ccdfa:/var/www/html# ll /usr/bin/phantomjs
-rwxrwxr-x+ 1 root root 67932064 Apr  5 13:40 /usr/bin/phantomjs*
root@d41d753ccdfa:/var/www/html# 
root@d41d753ccdfa:/var/www/html# 
root@d41d753ccdfa:/var/www/html# 
root@d41d753ccdfa:/var/www/html# 
root@d41d753ccdfa:/var/www/html# ls -la public/tmp/
total 356
drwxrwxrwx+  2 root root   4096 Apr  5 13:40 .
drwxrwxrwx  16 root root   4096 Apr  4 08:17 ..
-rw-r--r--   1 sail sail 349415 Apr  5 13:40 624c46bd6e71b2.tmp
-rw-r--r--   1 sail sail   1138 Apr  5 13:40 624c46bd6e9c93.pdf

Here user sail has all permission. Would you please suggest what extra I should do?

Thanks

Sebastian Morales commented on Apr 5, 2022

...

Sebastian Morales commented on Apr 6, 2022

Pls open file koolreport/export/Handler.php and add an exit command right before this line:

    exit; // add this line
    return new File($output);

Then try report export and check your temp dir /var/www/html/public/tmp for a newly created pdf and its content. Let us know the result. Tks,

FIMM commented on Apr 6, 2022

Thanks for the reply!

still doesnt work.

see when I copy the command from browser and command into shell_exec() into a.php

sail@d41d753ccdfa:/var/www/html$ php a.php 
<pre>1;/var/www/html/public/tmp/624d59ad853c93.pdf
sail@d41d753ccdfa:/var/www/html$ ls -lah /var/www/html/public/tmp/624d59ad853c93.pdf93.pdf
-rw-rw-r-- 1 sail root 141K Apr  6 09:14 /var/www/html/public/tmp/624d59ad853c93.pdf


root@d41d753ccdfa:/var/www/html# ll -lah public/tmp/
total 496K
drwsrwsrwt+  2 sail root 4.0K Apr  6 09:14 ./
drwxrwxrwx  16 root root 4.0K Apr  4 08:17 ../
-rw-r--r--   1 sail root 342K Apr  6 09:13 624d59ad851e52.tmp
-rw-rw-r--   1 sail root 141K Apr  6 09:14 624d59ad853c93.pdf

Above is okay, pdf has content.

However, when running direct from browser, it doesnt work, pdf become empty:

root@d41d753ccdfa:/var/www/html# ll -lah public/tmp/
total 356K
drwsrwsrwt+  2 sail root 4.0K Apr  6 09:19 ./
drwxrwxrwx  16 root root 4.0K Apr  4 08:17 ../
-rw-r--r--   1 sail root 342K Apr  6 09:19 624d5b124377f2.tmp
-rw-r--r--   1 sail root 1.2K Apr  6 09:19 624d5b124397a3.pdf

I have noticed permission became change in both scenario.

Any idea where it can be changed?

Sebastian Morales commented on Apr 6, 2022

Pls run the following command in your server's terminal to see exactly which user your web server use:

ps aux | egrep '(apache|httpd)'

Replace apache if you use another web server (nginx, etc).

Sebastian Morales commented on Apr 6, 2022

Another option is to set ownership of phantomjs to sail:

chown sail /usr/bin/phantomjs
FIMM commented on Apr 6, 2022

I have run the command you suggest:

ubuntu@fimm-app-stag:~$ ps aux | egrep '(nginx|httpd)'
root     4026496  0.0  0.0  55276   996 ?        Ss   Apr05   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 4026497  0.0  0.3  80460 31700 ?        S    Apr05   0:36 nginx: worker process
www-data 4026498  0.0  0.2  73168 24204 ?        S    Apr05   0:10 nginx: worker process
ubuntu   4061535  0.0  0.0   6432   716 pts/0    S+   09:52   0:00 grep -E --color=auto (nginx|httpd)

also did the command chown sail /usr/bin/phantomjs Outcome still same.

Sebastian Morales commented on Apr 6, 2022

It looks like your nginx user is www-data instead of sail. Pls try:

chown www-data /usr/bin/phantomjs

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