I intend to execute a shell script from PHP using shell_exec() in a simple file as follows:

<?php $result = shell_exec('sh /var/www/script.sh');
echo "<p>$res</p>;

This fails to produce any sort of output!
I have manually executed the script from the shell of the PHP web-server and it works fine and so there is supposedly no problem with the shell script.

Moreover, I have also tested the shell script execution in a PHP file with shell_exec('ls -altp'); and it worked fine producing the desired output. So, supposedly there are no shell script execution issues in my PHP environment.

Where should i search for to address this issue?
Your reply is highly appreciated!


Recommended Answers

All 2 Replies

There is something wrong with your echo

echo $result;

Using the command line or PHP for execution are actually two different user(groups). Make sure your web user (for PHP) is allowed to execute the command.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.