Did you figure this out? If so, what was the solution?
Failed to Launch Browser Process and Permissions Problem
Description:
I'm encountering an issue with the Browsershot package in my Laravel application while generating PDFs in a queue worker using Supervisor. The application works fine in my local environment but throws an error in my production setup on Ubuntu 22. I have tried various solutions, but I'm unable to resolve the issue.
Problem 1: Failed to Launch Browser Process:
When the queue worker tries to use Browsershot, it throws the following error:
Error: Failed to launch the browser process!
cmd_run.go:1046: WARNING: cannot create user data directory: cannot create snap home dir: mkdir /var/www/snap: permission denied
/system.slice/supervisor.service is not a snap cgroup
Problem 2: Permissions Issue:
After changing the user in Supervisor's configuration to www-data, I started encountering permission-related issues. For instance, Browsershot requires the www-data user to create directories and files for generating PDFs, but I'm unsure about the correct way to grant these permissions without compromising security.
What I've Tried:
- Adjusted ownership and permissions using chown and chmod for relevant directories.
- Confirmed that the www-data user has proper ownership for Laravel files and directories.
- Verified that Supervisor is configured to use the www-data user.
- Ensured that the system's temporary directory has appropriate permissions for the www-data user.
Environment:
- Laravel version: 10
- Browsershot version: 2.58
- Ubuntu version: Ubuntu 22
- Web server: Nginx
- Puppeteer: 17.1.3
Supervisor Config:
[program:your_queue]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/your/project/artisan queue:work --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=4
redirect_stderr=true
stdout_logfile=/var/log/your_queue.log
Question:
- How can I resolve the "Failed to launch the browser process" error that is occurring in my production environment?
- What is the correct and secure way to grant the www-data user permissions to create directories and files for Browsershot PDF generation?
I would greatly appreciate any guidance or insights into resolving these issues. Thank you in advance for your help!
Please or to participate in this conversation.