php shell_exec() command is not working

2020-01-31 07:13发布

I am trying to run a .sh file from php. I tried doing it with shell_exec(). but its not working I refered many questions related to this in stack overflow but could not solve

my php code is(web.php)

    <?php
    echo shell_exec('/var/www/project/xxe.sh');
    echo "done";
    ?>

only done is printed. but it is working from terminal(php /var/www/project/web.php)

In xxe.sh I am calling a python file

    python vin.py

I have also changed the file permission to 777 for both .sh n .py files please help

8条回答
看我几分像从前
2楼-- · 2020-01-31 07:40

On my host I had to give a different path for my php file to be executed from shell_exec(). This didn't work shell_exec('/usr/bin/php backgroundtask.php');.

While this did shell_exec('/opt/php/php-5.5.0/bin/php backgroundtask.php');.

You can visit this Reference.

查看更多
小情绪 Triste *
3楼-- · 2020-01-31 07:44

The problem is usually that when you exec code from within php it is run as the webservers user www-data in alot of linux distros. Normaly this user does not have an enviroment set up, and because of that no PATH. By using full paths in your files you can usually overcome this.

xxe.sh

/usr/bin/python /path/to/script/vin.py
查看更多
登录 后发表回答