Search code examples
phpubuntuselenium-grid

Executing commands via PHP exec on Ubuntu


I want to run a linux command via PHP exec() and my first command below executing in background at Ubuntu Server 22.04 perfectly -

<?php
$cmd = "java -jar /var/www/html/selenium-drivers/selenium-server-4.14.1.jar hub";
exec($cmd . " > /dev/null &");
?> 

But the very similar of my second command is not executing.

<?php
$cmd = "java -jar /var/www/html/selenium-drivers/selenium-server-4.14.1.jar node --port 5555 --selenium-manager true";
exec($cmd . " > /dev/null &");
?> 

I am unable to find out the reason why not working. Anybody please help?

Checked all necessay permissions of PHP and there is not issue of permissions. First command executing perfectly but the second is not.


Solution

  • I got fixed the issue with help of the comment by @ChrisHaas The actual issue was related to proper permission to www-data (Apache2) to access the directory. I given permission to the directory like -

    sudo chmod -R 777 /var/www/html/selenium-drivers

    and then I can execute the command

    <?php
    $cmd = "java -jar /var/www/html/selenium-drivers/selenium-server-4.14.1.jar node --port 5555 --selenium-manager true";
    exec($cmd . " > /dev/null &");
    ?>