Home  >  Q&A  >  body text

Is there a way to run Google Lighthouse with php + bash?

I try to use Google-Lighthouse on my website. I wrote a php file that calls 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=
VALUE=$(echo $SITE | awk -F'//' '{print }')
lighthouse $SITE --output html  --output-path ./path/$VALUE.html

There is also a simple php form named run_bash.php.

The question now is: If I run a bash script in the shell using Putty, it works fine, but when calling my URL and running run_bash.php, these errors show up on the 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'd love to know if anyone has ever done this? Or is this even possible?

P粉799885311P粉799885311228 days ago427

reply all(1)I'll reply

  • P粉541565322

    P粉5415653222024-03-29 00:36:05

    Ifinally found the answer! I have to run a bash script using function exec() in a php file as shown below.

    $output = exec('./rex.sh  ' . $text  );

    There is another important point. I changed the access level of all /var/www/ path files to www-data.

    reply
    0
  • Cancelreply