Set volume with php and amixer/pulseaudio












0














My problem is, that the following script executes in the terminal fine but on my Apache2-Webserver it doesn't do anything.



<?php
exec("/usr/bin/pactl set-sink-volume 0 60%");
?>


I can hear the music getting louder, when its executed from the terminal using



sudo php /var/www/html/test2.php


Other commands with exec work perfectly fine on the webserver. Working example:



<?php    
exec("/sbin/shutdown -r now");
?>


Setup:




  • Apache 2.4

  • PHP 7

  • Raspberry Pi 3b+

  • Raspian

  • Speaker connected via Headphone Jack


Thanks for any help in advance!










share|improve this question















migrated from superuser.com Dec 9 '18 at 12:37


This question came from our site for computer enthusiasts and power users.















  • Is apache (typically user www-data) part of the sudoers group?
    – Kasper Agg
    Dec 9 '18 at 13:47










  • I also think you shouldn't be invoking command line commands with sudo through a webapp. Why not add www-data to the group that is allowed to execute pactl?
    – Kasper Agg
    Dec 9 '18 at 13:49












  • Okay, how can I add www-data to the execution group?
    – Silvan
    Dec 9 '18 at 14:01










  • You could try google for that: google.nl/…
    – Kasper Agg
    Dec 9 '18 at 14:05
















0














My problem is, that the following script executes in the terminal fine but on my Apache2-Webserver it doesn't do anything.



<?php
exec("/usr/bin/pactl set-sink-volume 0 60%");
?>


I can hear the music getting louder, when its executed from the terminal using



sudo php /var/www/html/test2.php


Other commands with exec work perfectly fine on the webserver. Working example:



<?php    
exec("/sbin/shutdown -r now");
?>


Setup:




  • Apache 2.4

  • PHP 7

  • Raspberry Pi 3b+

  • Raspian

  • Speaker connected via Headphone Jack


Thanks for any help in advance!










share|improve this question















migrated from superuser.com Dec 9 '18 at 12:37


This question came from our site for computer enthusiasts and power users.















  • Is apache (typically user www-data) part of the sudoers group?
    – Kasper Agg
    Dec 9 '18 at 13:47










  • I also think you shouldn't be invoking command line commands with sudo through a webapp. Why not add www-data to the group that is allowed to execute pactl?
    – Kasper Agg
    Dec 9 '18 at 13:49












  • Okay, how can I add www-data to the execution group?
    – Silvan
    Dec 9 '18 at 14:01










  • You could try google for that: google.nl/…
    – Kasper Agg
    Dec 9 '18 at 14:05














0












0








0







My problem is, that the following script executes in the terminal fine but on my Apache2-Webserver it doesn't do anything.



<?php
exec("/usr/bin/pactl set-sink-volume 0 60%");
?>


I can hear the music getting louder, when its executed from the terminal using



sudo php /var/www/html/test2.php


Other commands with exec work perfectly fine on the webserver. Working example:



<?php    
exec("/sbin/shutdown -r now");
?>


Setup:




  • Apache 2.4

  • PHP 7

  • Raspberry Pi 3b+

  • Raspian

  • Speaker connected via Headphone Jack


Thanks for any help in advance!










share|improve this question















My problem is, that the following script executes in the terminal fine but on my Apache2-Webserver it doesn't do anything.



<?php
exec("/usr/bin/pactl set-sink-volume 0 60%");
?>


I can hear the music getting louder, when its executed from the terminal using



sudo php /var/www/html/test2.php


Other commands with exec work perfectly fine on the webserver. Working example:



<?php    
exec("/sbin/shutdown -r now");
?>


Setup:




  • Apache 2.4

  • PHP 7

  • Raspberry Pi 3b+

  • Raspian

  • Speaker connected via Headphone Jack


Thanks for any help in advance!







audio php raspberry-pi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 '18 at 15:23

























asked Dec 9 '18 at 10:27









Silvan

13




13




migrated from superuser.com Dec 9 '18 at 12:37


This question came from our site for computer enthusiasts and power users.






migrated from superuser.com Dec 9 '18 at 12:37


This question came from our site for computer enthusiasts and power users.














  • Is apache (typically user www-data) part of the sudoers group?
    – Kasper Agg
    Dec 9 '18 at 13:47










  • I also think you shouldn't be invoking command line commands with sudo through a webapp. Why not add www-data to the group that is allowed to execute pactl?
    – Kasper Agg
    Dec 9 '18 at 13:49












  • Okay, how can I add www-data to the execution group?
    – Silvan
    Dec 9 '18 at 14:01










  • You could try google for that: google.nl/…
    – Kasper Agg
    Dec 9 '18 at 14:05


















  • Is apache (typically user www-data) part of the sudoers group?
    – Kasper Agg
    Dec 9 '18 at 13:47










  • I also think you shouldn't be invoking command line commands with sudo through a webapp. Why not add www-data to the group that is allowed to execute pactl?
    – Kasper Agg
    Dec 9 '18 at 13:49












  • Okay, how can I add www-data to the execution group?
    – Silvan
    Dec 9 '18 at 14:01










  • You could try google for that: google.nl/…
    – Kasper Agg
    Dec 9 '18 at 14:05
















Is apache (typically user www-data) part of the sudoers group?
– Kasper Agg
Dec 9 '18 at 13:47




Is apache (typically user www-data) part of the sudoers group?
– Kasper Agg
Dec 9 '18 at 13:47












I also think you shouldn't be invoking command line commands with sudo through a webapp. Why not add www-data to the group that is allowed to execute pactl?
– Kasper Agg
Dec 9 '18 at 13:49






I also think you shouldn't be invoking command line commands with sudo through a webapp. Why not add www-data to the group that is allowed to execute pactl?
– Kasper Agg
Dec 9 '18 at 13:49














Okay, how can I add www-data to the execution group?
– Silvan
Dec 9 '18 at 14:01




Okay, how can I add www-data to the execution group?
– Silvan
Dec 9 '18 at 14:01












You could try google for that: google.nl/…
– Kasper Agg
Dec 9 '18 at 14:05




You could try google for that: google.nl/…
– Kasper Agg
Dec 9 '18 at 14:05












2 Answers
2






active

oldest

votes


















0














First check the group. One way is to use ls -lah /usr/bin/pactl. It should show amongst other information, the user and group who have permission. It also shows if the user, group and others have permission to execute at all.



To add an existing user account to a group on your system, use the usermodcommand, replacing examplegroup with the name of the group you want to add the user to andexampleusername  with the name of the user you want to add.



usermod -a -G examplegroup exampleusername



For example, to add the user www-data to the group music, use the following command:



usermod -a -G music www-data



Source



edit



Another way would be to allow all users to execute /usr/bin/pactl by adding execute bit to all.






share|improve this answer























  • I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
    – Silvan
    Dec 9 '18 at 14:45












  • I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
    – Kasper Agg
    Dec 9 '18 at 14:48










  • But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
    – Silvan
    Dec 9 '18 at 14:51












  • Are all flags the same those binaries? Are they for example 777 vs 755?
    – Kasper Agg
    Dec 9 '18 at 14:56










  • So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
    – Silvan
    Dec 9 '18 at 15:10





















0














My problem is solved. I'm writing files into a folder and a script checks this folder for the files and executes than the code to control the audio (I'm controlling it now with amixer instead of pactl).



Thanks for your suggestions anyway!






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53692361%2fset-volume-with-php-and-amixer-pulseaudio%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First check the group. One way is to use ls -lah /usr/bin/pactl. It should show amongst other information, the user and group who have permission. It also shows if the user, group and others have permission to execute at all.



    To add an existing user account to a group on your system, use the usermodcommand, replacing examplegroup with the name of the group you want to add the user to andexampleusername  with the name of the user you want to add.



    usermod -a -G examplegroup exampleusername



    For example, to add the user www-data to the group music, use the following command:



    usermod -a -G music www-data



    Source



    edit



    Another way would be to allow all users to execute /usr/bin/pactl by adding execute bit to all.






    share|improve this answer























    • I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
      – Silvan
      Dec 9 '18 at 14:45












    • I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
      – Kasper Agg
      Dec 9 '18 at 14:48










    • But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
      – Silvan
      Dec 9 '18 at 14:51












    • Are all flags the same those binaries? Are they for example 777 vs 755?
      – Kasper Agg
      Dec 9 '18 at 14:56










    • So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
      – Silvan
      Dec 9 '18 at 15:10


















    0














    First check the group. One way is to use ls -lah /usr/bin/pactl. It should show amongst other information, the user and group who have permission. It also shows if the user, group and others have permission to execute at all.



    To add an existing user account to a group on your system, use the usermodcommand, replacing examplegroup with the name of the group you want to add the user to andexampleusername  with the name of the user you want to add.



    usermod -a -G examplegroup exampleusername



    For example, to add the user www-data to the group music, use the following command:



    usermod -a -G music www-data



    Source



    edit



    Another way would be to allow all users to execute /usr/bin/pactl by adding execute bit to all.






    share|improve this answer























    • I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
      – Silvan
      Dec 9 '18 at 14:45












    • I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
      – Kasper Agg
      Dec 9 '18 at 14:48










    • But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
      – Silvan
      Dec 9 '18 at 14:51












    • Are all flags the same those binaries? Are they for example 777 vs 755?
      – Kasper Agg
      Dec 9 '18 at 14:56










    • So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
      – Silvan
      Dec 9 '18 at 15:10
















    0












    0








    0






    First check the group. One way is to use ls -lah /usr/bin/pactl. It should show amongst other information, the user and group who have permission. It also shows if the user, group and others have permission to execute at all.



    To add an existing user account to a group on your system, use the usermodcommand, replacing examplegroup with the name of the group you want to add the user to andexampleusername  with the name of the user you want to add.



    usermod -a -G examplegroup exampleusername



    For example, to add the user www-data to the group music, use the following command:



    usermod -a -G music www-data



    Source



    edit



    Another way would be to allow all users to execute /usr/bin/pactl by adding execute bit to all.






    share|improve this answer














    First check the group. One way is to use ls -lah /usr/bin/pactl. It should show amongst other information, the user and group who have permission. It also shows if the user, group and others have permission to execute at all.



    To add an existing user account to a group on your system, use the usermodcommand, replacing examplegroup with the name of the group you want to add the user to andexampleusername  with the name of the user you want to add.



    usermod -a -G examplegroup exampleusername



    For example, to add the user www-data to the group music, use the following command:



    usermod -a -G music www-data



    Source



    edit



    Another way would be to allow all users to execute /usr/bin/pactl by adding execute bit to all.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 9 '18 at 14:50

























    answered Dec 9 '18 at 14:12









    Kasper Agg

    7217




    7217












    • I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
      – Silvan
      Dec 9 '18 at 14:45












    • I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
      – Kasper Agg
      Dec 9 '18 at 14:48










    • But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
      – Silvan
      Dec 9 '18 at 14:51












    • Are all flags the same those binaries? Are they for example 777 vs 755?
      – Kasper Agg
      Dec 9 '18 at 14:56










    • So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
      – Silvan
      Dec 9 '18 at 15:10




















    • I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
      – Silvan
      Dec 9 '18 at 14:45












    • I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
      – Kasper Agg
      Dec 9 '18 at 14:48










    • But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
      – Silvan
      Dec 9 '18 at 14:51












    • Are all flags the same those binaries? Are they for example 777 vs 755?
      – Kasper Agg
      Dec 9 '18 at 14:56










    • So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
      – Silvan
      Dec 9 '18 at 15:10


















    I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
    – Silvan
    Dec 9 '18 at 14:45






    I executed the following command in the terminal an it worked: sudo -u pi /usr/bin/pactl set-sink-volume 0 20% When I execute it on the webserver it doesn't work. In the sudoers file I have added, that it doesn't need a password to execute this specific command.
    – Silvan
    Dec 9 '18 at 14:45














    I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
    – Kasper Agg
    Dec 9 '18 at 14:48




    I do not understand your comment. In order for apache to execute the same command without using sudo, the apache user (www-data) needs to be added to the group of the executables' group.
    – Kasper Agg
    Dec 9 '18 at 14:48












    But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
    – Silvan
    Dec 9 '18 at 14:51






    But the sbin folder requires sudo rights too and the shutdown command in this folder works from the website, and I didn't change anything on the permissions
    – Silvan
    Dec 9 '18 at 14:51














    Are all flags the same those binaries? Are they for example 777 vs 755?
    – Kasper Agg
    Dec 9 '18 at 14:56




    Are all flags the same those binaries? Are they for example 777 vs 755?
    – Kasper Agg
    Dec 9 '18 at 14:56












    So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
    – Silvan
    Dec 9 '18 at 15:10






    So I changed the permissions of the /usr/bin/pactl to the exact same as /sbin/shutdown ones, still not working, the flag is now 777.
    – Silvan
    Dec 9 '18 at 15:10















    0














    My problem is solved. I'm writing files into a folder and a script checks this folder for the files and executes than the code to control the audio (I'm controlling it now with amixer instead of pactl).



    Thanks for your suggestions anyway!






    share|improve this answer


























      0














      My problem is solved. I'm writing files into a folder and a script checks this folder for the files and executes than the code to control the audio (I'm controlling it now with amixer instead of pactl).



      Thanks for your suggestions anyway!






      share|improve this answer
























        0












        0








        0






        My problem is solved. I'm writing files into a folder and a script checks this folder for the files and executes than the code to control the audio (I'm controlling it now with amixer instead of pactl).



        Thanks for your suggestions anyway!






        share|improve this answer












        My problem is solved. I'm writing files into a folder and a script checks this folder for the files and executes than the code to control the audio (I'm controlling it now with amixer instead of pactl).



        Thanks for your suggestions anyway!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 10 '18 at 14:38









        Silvan

        13




        13






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53692361%2fset-volume-with-php-and-amixer-pulseaudio%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Plaza Victoria

            Brian Clough

            Cáceres