Why am I not able to execute this bash script using php? I have tried exec()
as well as shell_exec()
.
index.php
<?php
$old = getcwd();
echo $old;
chdir($old);
$message=exec("a.sh");
print_r($message);
?>
a.sh
#!bin/bash
echo "i am a" > /opt/lampp/htdocs/a.txt
echo "Done"
I have tried chdir
as suggested here, as well as I have checked my disable_functions
in php.ini
, it doesn't have anything. I have also checked other questions, but none seem to solve my problem.
chdir($old)
twice? Is that a typo?$old
shows the correct path of a.sh. Asindex.php
anda.sh
are in the same dir.chdir
was there because I copied that from somewhere, then edited the 1st chdir but not the second.a.sh
have#!/bin/bash
as the first line? Have you triedexec("/bin/bash a.sh")
bin
so it reads#!/bin/bash