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
It finally worked by installing puppeteer@21 instead of the last version.
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)