recently I'm doing a small project, and a part of it involves running a python script using PHP. to explain further:
Python:
from playsound import playsound
playsound("path/of/the/audio")
print("playsound executed")
PHP:
echo system('python3 pythonapp.py');
I used a print function to make sure my playsound func executed properly which it did, I even double checked my python file by running it directly in the terminal which plays the audio without any problem, what I would like to know, is why when I used PHP to call the python script it wont play the audio. but using phpmyadmin, the output "playsound executed" is shown.
Thank you for your time! hope you can help me resolve this.
Edit: Ubuntu is running on a Raspberry Pi 4B and I'm using phpmyadmin/apache2 to run my php script
1 Answer 1
One likely cause is missing permissions: your script works when you run it as the pi
user, but apache runs it as www-data
.
Try sudo -u www-data python3 pythonapp.py
and see if it still works. If not, you'll need to give permissions to all users to access your script and the sound file.
You will also need to add www-data
user to audio
group.
paplay path/of/the/audio
. Also are you running in Ubuntu server or desktop?