Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jweitz's avatar
Level 12

shell_exec not working in Laravel scheduler

I am trying to execute a shell_exec('pacmd list-sink-inputs') command via the task scheduler, with no luck I even included the full path to "/usr/bin/pacmd". I is running the user crontab, I added the user to www-data group as I think the php script is spawned by www-data... It works fine and as expected when executed directly using php artisan from the user's terminal. What am I missing or what can I do to fix this?

0 likes
5 replies
HenryNicholls's avatar

My project right now is taking an old app I wrote in plain PHP a https://appvalley.onl/ nd rewriting it in laravel. I'm working with some great YouTube content courses I've found for Laravel 8. I'm still wrapping my head around the whole MVC concept... I feel like the view makes sense and I've started working with the controllers somewhat but not models yet.. that's going to be next.. just wondering if anyone had a cool analogy they could share about it or anything you feel would be helpful is welcomed !!

jweitz's avatar
Level 12

@HenryNicholls You seem to have replied to my question instead of creating a new discussion... not to worry you will find great resources at @Laracast its worth every minute you can spend on it. I can't really compare it with anything else its just that great... the learning curve isn't that steep if you already have some experience, if you haven't yet signed up for @Laracast video content do so there is no better content than this for learning about @Laravel and its ecosystem... Just learning as much as you can and build something great!

Snapey's avatar

have you tried running cron actually as www-data user?

jweitz's avatar
Level 12

Thanks for your reply Snapey... I have tried running cron as www-data, it then appears the cron doesn't run at all. At least with running as user I get log information... just shell_exec returning null, having said that doing a test with something like shell_exec('ls -l') works fine, so it executes some commands.

jweitz's avatar
Level 12

The issue were resolved -- using shell_exec('XDG_RUNTIME_DIR=/run/user/$(id -u) /usr/bin/pacmd list-sink-inputs')

Hope it can help someone...

1 like

Please or to participate in this conversation.