0

I am trying to run a bash file from a PHP file. The script is in the directory /home/hostitec, which is called registro.sh The php file, where I am running the bash file (giving him some variables as parameters), is in /var/www/ftpdir/Hostitec/include/php

The script is actually working, the syntax is fine. But the php file does not run it, maybe because of the directory

This is my PHP syntax for running the bash file:

$old_path = getcwd();
chdir("/home/hostitec");
$output = shell_exec("./registro.sh '".$var1."' '".$var2."' '".$var3."' '".$var4."' '".$var5."'");
chdir($old_path);
echo "<pre>".$output."</pre>";

FINAL PHP syntax

$output = shell_exec("home/hostitec/registro.sh '".$var1."' '".$var2."' '".$var3."' '".$var4."' '".$var5."'");
echo "<pre>".$output."</pre>";
  • What are the permissions of registro.sh and /home/hostitec? Can you do a ls -ld /home/hostitec and ls -l /home/hostitec/registro.sh? Also, can you check if chdir returns TRUE or FALSE? – Mr Shunz Sep 4 '18 at 13:21
  • @Antonio: it works on my computer. What is the output of running php /var/www/ftpdir/Hostitec/include/php/yourfile.php – Helio Sep 4 '18 at 13:25
  • These are the permissions of ls -l -rwxrwxrwx 1 hostitec hostitec 1291 sep 4 14:53 registro.sh. And this are the permissions of ls -ld drwxr-xr-x 16 hostitec hostitec 4096 sep 4 14:53. About chdir, it returns me this bash: chdir: order was not found @MrShunz – Antonio Sep 4 '18 at 13:32
  • 1
    @Antoni @Helio what I don't understand is that PHP function chdir should NOT return a string. That looks like a bash error, not a PHP one. As per manual ( php.net/manual/en/function.chdir.php ) chdir should return true or false. As a simple test running a php scritp with just echo chdir('/a/b/c') ? 'yes' : 'no' gives a warning PHP Warning: chdir(): No such file or directory (errno 2) in /tmp/test.php on line 2 and "no" as output. – Mr Shunz Sep 4 '18 at 13:43
  • 1
    @Antonio: you can execute an absolute path: shell_exec("/home/hostitec/registro.sh '".$var1."' '".$var2."' '".$var3."' '".$var4."' '".$var5."'"); – Helio Sep 4 '18 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.