I am trying to execute an audio file running as a python subprocess(shell=True) using mpg321. just running python script from terminal as user works, running the audio file through mpg321 from terminal as user works. However when my website calls a php script to execute this python script mpg321 returns an error. I know the most obvious answer is to check permissions, however this system has been working fine until now since when I set it up a year ago, I fixed the permissions by giving apache full access ( made it run as user, I know its bad, but only thing that worked then). Recently, had issues with speakerphone connecting using pulseaudio due to not having hands free profile, I changed to pipewire. Bluetooth issues are sorted, but audio (via php) problem emerged.
The error I get when playing mpg321 (via php) is 'Can't find a suitable libao driver (is device in use)'. obviously, I tried to check permissions, they are all set. www-data and user are also part of the audio group, checked whoami and apache user they are user.
so next I did apt install libao driver, suprsingly the error went away, mpg321 processed the mp3 file but NO AUDIO COULD BE HEARD. I looked at pavucontrol, alsamixer to see if its muted etc, NO!. Forums suggested should try -o alsa with mpg321 and voila I get the same error regarding libao again, meanwhile via terminal with or without -o alsa sound works.
Its such a weird issue, I am running out of options to debug.