Ubuntu 18 VM in AWS.
$return = exec("node -v", $o, $e);
var_dump($retu);
var_dump($o);
var_dump($e);
Output:
string(8) "v10.16.3" array(1) { [0]=> string(8) "v10.16.3" } int(0)
- So node is installed properly.
- exec is able to get node version.
However, $return = exec("node /var/www/savePdf.js someUrl someName", $o, $e); is not working.
Output:
string(0) "" array(0) {} int(1)
node /var/www/savePdf.js someUrl someName is working in the terminal, the PDF file is generated and getting saved properly. How can this issue be addressed?
<?php echo exec('whoami'); ?> outputs as nt authority\system
The var/www -R is owned by www-data.
On researching some tutorials I added the following lines to sudoers file (ignoring the warnings mentioned there about the security, so that I can sudo the exec command),
$return = exec("sudo node /var/www/savePdf.js someUrl someName", $o, $e); // no difference
The savePdf.js contains GoogleChrome/puppeteer code for generating PDF from URL as follows,
'use strict';
const puppeteer = require('/var/www/mysitename/public_html/node_modules/puppeteer');
const url = process.argv[2], name = process.argv[3];
(async() => {
const browser = await puppeteer.launch(
{
executablePath: '/usr/bin/google-chrome',
args: ['--no-sandbox', '--disable-setuid-sandbox']}
);
const page = await browser.newPage();
await page.goto(url, {waitUntil: 'networkidle2'});
await page.pdf({
path: '/var/www/mysitename/public_html/resources/logs/'+name+'.pdf',
format: 'A4',
printBackground: true,
margin: {
top: "1cm",
bottom: "1cm",
left: "1cm",
right: "1cm",
}
});
await browser.close();
})();

console.logandtry & catchto track the run-time error? - BadPiggie> /dev/null &. However, It takes 3 to 4x times to generate the PDF when calling from exex/shell_exec compared to terminal. - Mr Cathode