how to execute a linux executable file in linux server using shell_exec in php?
i made a php program in windows server and here is my code:
$cmdline = "filenameexe" . -fast . " -infile=" . $target_path . "-gapdist= -gapopen= -endgaps=";
$result = shell_exec($cmdline);
in windows, filenameexe (without its extension .exe) will run, the exe file just resides in same folder where the php pages reside.
and the exe file accepts parameters like -fast, -infile=, etc.
now i need to upload my work in a linux server. what will be the right command in using shell_exec()?
i know that what i used in my program is a windows executable file so i will provide a linux executable file for this.
i just need to know the command in linux in order for my project to work. thanks in advance.
The same thing, only it is better to specify full path, because unlike Windows, the current directory is not not always included in the PATH on Unix.
$dir = basename(__FILE__);
$exe = $dir . "/linux-exe-file";
….
$result = shell_exec($cmdline);
By the way, dot (./) may not work, because it signifies "current directory", not necessarily the directory where your PHP file is located. The two quite possibly may be different.
Just add a ./ to the begging of the filename string.
$cmdline ="./filename"…
./ signifies that it should look in the current directory. It wont run by just including the filename unless the directory is in the PATH.
References :
In Linux, you can run any executable in the current path by simply typing its name. If the executable you want to run isn’t in a system path, you may need to type out the whole path to the executable.
References :
The same thing, only it is better to specify full path, because unlike Windows, the current directory is not not always included in the PATH on Unix.
$dir = basename(__FILE__);
$exe = $dir . "/linux-exe-file";
….
$result = shell_exec($cmdline);
By the way, dot (./) may not work, because it signifies "current directory", not necessarily the directory where your PHP file is located. The two quite possibly may be different.
References :
You do it the same, but you will need to get the full relative or absolute path to the executable. It it’s in the same directory, the relative path is ./
For instance, if the executable is called
program1
the path would look something like this..
./program1 (note the ‘.’ before the slash)
if you need to supply the absolute path, it would be, for instance
/var/www/html/website/app/program1
References :