Issue
My system is : Ubuntu 20.04 Php 7.4 Nginx
I have a php file with following content in /var/www/hamrah.com/create.php path :
<?php
$output = shell_exec('bash flutter create test');
echo "<pre>$output</pre>";
i run this command in terminal and And this command executes correctly (creates a flutter project for me)
cd /var/www/hamrah.com && php /var/www/hamrah.com/create.php
BUT !
But when I put this command in Crontab, the command is not executed properly and gives an error
In Crontab :
* * * * * cd /var/www/hamrah.com && php /var/www/hamrah.com/create.php
Note: If I put shell_exec(' bash ls')
instead of shell_exec('bash flutter creat test')
in the php file, it will run well and some commands like the flutter create
command will not be executed.
error : bash: flutter: No such file or directory
Solution
You can test
<?php
$output = shell_exec('bash /opt/flutter/bin/flutter create test');
echo "<pre>$output</pre>";
Answered By - Amir Hossein Habibi Answer Checked By - Gilberto Lyons (WPSolving Admin)