I try to use Google-Lighthouse on my website. I wrote a php file that called a bash-script to run lighthouse-cli.
run_bash.php :
<?php
if(isset($_GET['subject2'])) {
$text = $_GET['subject2'];
$text = escapeshellarg($text);
$command = './rex.sh 2>&1 >> path/mylog ' . $text ;
$output = shell_exec($command);
echo "<pre>$output</pre>";
}
?>
my bash script:
rex.sh
#!/bin/bash
SITE=""
SITE=$1
VALUE=$(echo $SITE | awk -F'//' '{print $2}')
lighthouse $SITE --output html --output-path ./path/$VALUE.html
and a simple php form that called run_bash.php
well.
now problem is:
if I run my bash script in shell with Putty it works well but when call my URL and run run_bash.php
these error show at browser:
Sun, 05 Jun 2022 19:20:59 GMT LH:ChromeLauncher Waiting for browser...............................................................................................
Sun, 05 Jun 2022 19:21:00 GMT LH:ChromeLauncher Waiting for browser.................................................................................................
Sun, 05 Jun 2022 19:21:00 GMT LH:ChromeLauncher Waiting for browser...................................................................................................
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher Waiting for browser.....................................................................................................
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher Waiting for browser.......................................................................................................
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher:error connect ECONNREFUSED 127.0.0.1:33989
Sun, 05 Jun 2022 19:21:01 GMT LH:ChromeLauncher:error Logging contents of /tmp/lighthouse.dVx18OP/chrome-err.log
Unable to connect to Chrome
I'm curious to know if anyone has ever done this? Or is it possible at all?
CodePudding user response:
I finally found the answer!
I had to use function exec()
in the php file to run the bash script as bellow.
$output = exec('./rex.sh ' . $text );
And another important point.
I changed the access level of all /var/www/
path files to www-data
.