skip to Main Content

When I try to run a Puppeteer command from PHP using the exec function, I get this error:

Error: EACCES: permission denied, stat '/root/.config/puppeteer'

Do you know how to resolve this problem?

I tried to set the owner and the group of the folder /root/.config/puppeteer to www-data and set the chmod to 777 but this didn’t work.

I also tried this:

process.env.PUPPETEER_DOWNLOAD_PATH = '/var/www/.chromium-browser-snapshots';
process.env.PUPPETEER_CONFIG = '/var/www/.puppeteer';
process.env.PUPPETEER_CACHE_DIR = '/var/www/.puppeteer';
process.env.PUPPETEER_USER_DATA_DIR = '/var/www/.puppeteer';

2

Answers


  1. Chosen as BEST ANSWER

    It finally worked by installing puppeteer@21 instead of the last version.


  2. Maybe it’s because puppeteer cannot find the executable for chrome, when it is executed from PHP.

    Add to your server code: (change executablePath where the chrome executable is at)

    const browser = await puppeteer.launch({
      headless: 'new',
    
      // must so it works from php's `shell_exec`
      executablePath: 'C:\Program Files\Google\Chrome\Application\chrome.exe',
    
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search