Execute perl in PHP
Use full path to execute the script.
exec("/usr/bin/perl /full/path/to/Script.pl $username $password",$output);
Regards,
Comments
-
Suresh kumar almost 2 years
Possible Duplicate:
Calling Perl script from PHP and passing in variables, while also using variablized perl script nameI want to execute a perl script through PHP. I use
exec()
to execute the perl script. It works in my machine but does not work on the server. The Server is based on CentOS Linux.I gave full permission (777) to both the PHP and the perl script file. When I try to execute, I get the following error in error_log
sh: /perl: No such file or directory
I tried to execute using the following ways
exec("perl -w Script.pl $username $password",$output); exec("/usr/bin/perl -w Script.pl $username $password",$output); exec("/usr/bin/perl Script.pl $username $password",$output);
I also tried by using the
system
function$output = system("perl Script.pl $username $password");
Nothing happening when I try this.
I also tried to execute perl by using the
passthru()
functionpassthru("/usr/bin/perl -w Script.pl $username $password",$output);
When I execute this line,
$output
prints 127 and nothing happens in the script.I checked whether file is executable or not with the
is_executable()
function. It shows that the file is not executable.Code as below
$file = 'Script.pl'; if (is_executable($file)) { echo $file.' is executable'; } else { echo $file.' is not executable'; }
If I execute perl through the terminal, it works fine but when I try to execute through PHP, it is not working.
-
Suresh kumar almost 12 yearsAlready i try this.. Not working.
-
KingsInnerSoul almost 6 yearsPHP executes as the apache user
www-data
. Your script is probably needs to run as a sudo, but PHP wont allow it. At least fordebiab
, runvisudo
, and then addwww-data ALL=(ALL:ALL) NOPASSWD: /pat/to/your/script.pl
, then change permission so only root can edit the file (safety):sudo chown root:someuser /path/to/your/script.pl
, and lastly make it executablesudo chmod u+rwx /path/to/your/script.pl